Skip to main content

Environment

Inherits from Instance

Environment is the primary object intended for storing active objects in the place. Objects not inside of the Environment will not be rendered or physically interact with the world.

Not Creatable Service

Summary

Properties

Methods

Details

The job of the Environment is to hold objects that exist in the 3D world, effectively Parts. For Parts, this means they will be rendered, and physically interact with other parts and the world. For other objects, it means that they will render.

Understanding this behavior is important, as it means objects can be removed from the Environment when they are not needed. For example, map Models can be removed when a different map is being played on. Objects that are not needed in the 3D world can be stored inside of Hidden or ServerHidden

Accessing the Environment You use game["Environment"] in order to access the Environment.

Notes

  • It is not possible to delete the Environment
  • The Environment will automatically clean up Parts that fall beneath PartDestroyHeight
  • The client's Camera is stored under the environment and can be accessed via game["Environment"]["Camera"]
  • You can set the fog of the world under the Environment properties
  • You can set the Skybox of the world under the Environment properties

Properties

AutoGenerateNavMesh

Environment.AutoGenerateNavMesh: bool

Determines whether or not to automatically build a navigation mesh for NPC pathfinding. This property is disabled by default so there are no performance issues with larger maps.

When updating the map, even if the property is set to true, you will still have to manually call the Environment:BuildNavMesh() method.

FogColor

Environment.FogColor: Color

The color of the fog. Fog is a visual effect that makes the world look like it is covered in a colored mist.

Example

Change the fog color to white:

game["Environment"].FogColor = Color.New(1, 1, 1, 1)

FogEnabled

Environment.FogEnabled: boolean

Whether or not fog is enabled.


FogStartDistance

Environment.FogStartDistance: float

The distance from the camera at which fog starts to appear


FogEndDistance

Environment.FogEndDistance: float

The distance from the camera at which fog is fully opaque


Gravity

Environment.Gravity: Vector3=Vector3.New

Parameters:

ParameterTypeDefaultDescription
0any-
-75any-
0any-

The direction and strength of gravity in the world


PartDestroyHeight

Environment.PartDestroyHeight: float

The height at which unanchored parts are destroyed when they fall below it.

Example

game["Environment"].PartDestroyHeight = -2000

Skybox

Environment.Skybox: SkyboxPreset

The default skybox preset to use for the world, if no ImageSky is present.


Methods

CreateExplosion

Environment:CreateExplosion(Position: Vector3, Radius: float, Force: float, affectAnchored: bool, callback: function, damage: float)

Parameters:

ParameterTypeDefaultDescription
PositionVector3-
Radiusfloat10
Forcefloat5000
affectAnchoredbooltrue
callbackfunctionnil
damagefloat10000

Creates a deadly explosion killing players and applying force to parts at the given position.

Example

game["Environment"]:CreateExplosion(Vector3.New(0, 0, 0), 30, 5000, false, nil, 10)
When set to true, AffectAnchored will unanchor parts within the explosion radius.
Callback gets called for each part within explosion radius.

OverlapBox

Environment:OverlapBox(position: Vector3, size: Vector3, rotation: Vector3, ignoreList: array): Instance[]

Parameters:

ParameterTypeDefaultDescription
positionVector3-
sizeVector3-
rotationVector3-
ignoreListarrayInstance[]

Returns a list of instances intersecting with the box in the given position, size and rotation.

A demo of this method is available here.

Example

local intersections = game["Environment"]:OverlapBox(Vector3.New(0,0,0), Vector3.New(2,2,3), Vector3.New(0,0,0))

for i,v in ipairs(intersections) do
print(v.Name .." is intersecting the box!")
end

OverlapSphere

Environment:OverlapSphere(position: Vector3, radius: float, ignoreList: array): Instance[]

Parameters:

ParameterTypeDefaultDescription
positionVector3-
radiusfloat-
ignoreListarrayInstance[]

Returns a list of instances intersecting with the sphere in the given position and radius.

Example

local intersections = game["Environment"]:OverlapSphere(Vector3.New(100,0,45), 25)

for i,v in ipairs(intersections) do
print(v.Name .." is intersecting the sphere!")
end

Raycast

Environment:Raycast(origin: Vector3, direction: Vector3, maxDistance: float, ignoreList: array): RayResult

Parameters:

ParameterTypeDefaultDescription
originVector3-
directionVector3-
maxDistancefloatinfinite
ignoreListarrayInstance[]

Casts a ray from origin with a specified direction and returns a RayResult for the first hit object.

Example

local hit = game["Environment"]:Raycast(barrel.Position, barrel.Forward)

if hit and hit.Instance:IsA("Player") then
hit.Instance.Health = 0
end

RaycastAll

Environment:RaycastAll(origin: Vector3, direction: Vector3, maxDistance: float, ignoreList: array): RayResult[]

Parameters:

ParameterTypeDefaultDescription
originVector3-
directionVector3-
maxDistancefloatinfinite
ignoreListarrayInstance[]

Casts a ray from origin with a specified direction and returns a RayResult array for all hit objects.

Example

local hits = game["Environment"]:RaycastAll(Vector3.New(0, 10, 0), Vector3.New(0, -1, 0), 100)

for i, hit in pairs(hits) do
print("Hit at " .. hit.Position .. "!")
end

RebuildNavMesh

Environment:RebuildNavMesh(root: Instance)

Parameters:

ParameterTypeDefaultDescription
rootInstancenil

Rebuilds the navigation mesh which determines the empty space where NPCs can pathfind in.

Example

game["Environment"]:RebuildNavMesh()
# or
game["Environment"]:RebuildNavMesh(game["Workspace"]["Map"])

GetPointOnNavMesh

Environment:GetPointOnNavMesh(position: Vector3, maxDistance: float): Vector3

Parameters:

ParameterTypeDefaultDescription
positionVector3-
maxDistancefloatinfinite

Returns a point on the navigation mesh at the given position.

Properties