Skip to main content
Returns the global environment table of a Lua thread - for a LocalScript thread, the exact same table getsenv(script) returns.
When t belongs to a LocalScript, gettenv(t) returns the same table as getsenv(script) (rawequal true). gettenv(t).script is the owning script, the same Instance getscriptfromthread(t) returns.

Parameters

Returns

table - the thread’s global environment. For a LocalScript thread it is identical (rawequal) to getsenv(thatScript): direct keys are the script’s own globals, Roblox globals (game, print, task) resolve through the metatable. Carries a .script field pointing at the owning script.

Example

In a Roblox game, confirm a thread’s environment is the same table as its script’s environment.
Already holding the thread’s env table from gettenv(t)? Its .script field is the owning script - the same Instance getscriptfromthread(t) returns, without the extra call.