ReferenceScripts

getsenv

Returns the globals table of a running script.

Syntax

getsenv(script: LocalScript | ModuleScript) -> table?

Also available as

get_senv

Parameters

ParameterTypeDescription
scriptLocalScript or ModuleScriptA running script.

Returns

TypeDescription
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

These are Game executor contracts. Check build requirements and session lifetimes before using them.