getsenv

Finds a script's live environment.

Syntax

Signature
getsenv(Script: Instance) -> table?

Aliases

This function has no aliases.

Parameters

ParameterTypeDescription
ScriptInstanceOriginal script wrapper. A different reference proxy does not pass the raw identity check.

Returns

TypeDescription
table?First matching live environment, or nil.

Notes

Searches live Luau closures in the current VM for an environment whose raw script field is the exact Script table. Environments created by getscriptclosure are excluded. Returns nil if no matching live closure is found.

Example

Luau
local Script = getscripts()[1]
assert(Script, "No captured script available")
local Result = getsenv(Script)
print(Result)