getsenv Synchronous
Get the environment table associated with an executing script. Use it to inspect values a script sees without assuming they are in your own environment.
Luau
getsenv(script: ScriptInstance) -> TableParameters
| Parameter | Type | Description |
|---|---|---|
script | ScriptInstance | Script Instance whose running environment is needed. |
Returns
TableThe script’s environment table.
Usage notes
A script without an available running environment raises an error. getmenv is a distinct API for ModuleScript environments.
Example
Luau
local candidate = getrunningscripts()[1]
if candidate then
local ok, environment = pcall(getsenv, candidate)
if ok then
local count = 0
for _ in pairs(environment) do count += 1 end
print("Environment entries:", count)
end
end