Skip to content

Environment

Service Object

This object is automatically created by Polytoria. Additionally, scripts cannot change its parent.

Not newable

This object cannot be created by scripts using Instance.New().

Environment is the primary object intended for storing active objects in the place.

Inherits Instance

Methods

CreateExplosion → void

Parameters

Position [ Vector3 ]

Radius [ float = 10 ]

Force [ float = 5000 ]

affectAnchored [ boolean = true ]

callback [ function = nil ]

damage [ float = 10000 ]

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 → Instance[]

Parameters

position [ Vector3 ]

size [ Vector3 ]

rotation [ Vector3 ]

ignoreList [ array = Instance[] ]

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 → Instance[]

Parameters

position [ Vector3 ]

radius [ float ]

ignoreList [ array = Instance[] ]

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 → RayResult

Parameters

origin [ Vector3 ]

direction [ Vector3 ]

maxDistance [ float = infinite ]

ignoreList [ array = Instance[] ]

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 → RayResult

Parameters

origin [ Vector3 ]

direction [ Vector3 ]

maxDistance [ float = infinite ]

ignoreList [ array = Instance[] ]

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

Properties

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 : boolean

Whether or not fog is enabled.

FogStartDistance : float

The distance from the camera at which fog starts to appear

FogEndDistance : float

The distance from the camera at which fog is fully opaque

Gravity : Vector3 = Vector3.New(0, -75, 0)

The direction and strength of gravity in the world

PartDestroyHeight : int

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

Example

game["Environment"].PartDestroyHeight = -2000

Skybox : SkyboxPreset

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