Skip to content

getsenv

Only works on active scripts

This function will throw an error if the script isn't currently running. If the script is running but on a different Lua State (such as on an Actor), the function will return nil instead.

getsenv returns the global environment table of a given Script, LocalScript, or ModuleScript.

This environment contains all global variables, functions available to the target script, such as custom-defined functions or state values.

function getsenv(script: BaseScript | ModuleScript): { [any]: any } | nil

Parameters

Parameter Description
script The script instance whose environment should be retrieved.

Example

Accessing a script's internal environment
1
2
3
4
5
local animate = game.Players.LocalPlayer.Character:FindFirstChild("Animate")

local env = getsenv(animate)

print(typeof(env.onSwimming)) -- Output: function