getsenv
Returns the globals table of a running script.
Syntax
getsenv(script: LocalScript | ModuleScript) -> table?
Also available as
get_senv
Parameters
| Parameter | Type | Description |
|---|---|---|
script | LocalScript or ModuleScript | A running script. |
Returns
| Type | Description |
|---|---|
table? | The script's global environment, or nil when it has none. |
Description
Every global function and variable the script defined is a field of this table, so you can read state or call the script's own functions. Local variables are not included; read them with getupvalues or getstack.
Example
local env = getsenv(game.Players.LocalPlayer.PlayerScripts.ClientMain)
for name, value in env do
print(name, typeof(value))
end
Notes
- A script that has not run has no environment and returns
nil.
These are Game executor contracts. Check build requirements and session lifetimes before using them.
