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.

Syntax
Luau
getsenv(script: ScriptInstance) -> Table

Parameters

Function parameters
ParameterTypeDescription
scriptScriptInstanceScript Instance whose running environment is needed.

Returns

Table

The 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

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
Kawaii documentation