Skip to main content
Returns the script environment of a running LocalScript.
The simplest way to picture it: getsenv(script) hands back the same table getfenv() would return if you called it from inside that running script. Most commonly used to read or rewrite a running LocalScript’s globals - spoof config flags, capture debug state, all without modifying the source. getsenv only works once the script is running. A LocalScript that has not started executing yet has no environment to return. The table’s direct keys are the script’s own globals. GLOBAL_VAR = true at the top of the script becomes the GLOBAL_VAR key; locals declared with local never reach the table - Luau’s compiler inlines them into stack slots and upvalues. Roblox globals (game, print, task, require) reach the table through its metatable’s __index instead of as direct keys. For a LocalScript thread, gettenv(t) returns the same table (rawequal true).

Parameters

Returns

table - the LocalScript’s global environment.

Example

Pick a target LocalScript with a known boolean global (e.g. an admin script’s IS_ADMIN flag), read its current value, flip it, observe the script’s behavior change.
For most jobs, reach for getscriptclosure instead. getsenv only shows globals the script declares on purpose, and modern scripts rarely expose any - they keep everything local. The closure getscriptclosure hands back feeds debug.getconstants and debug.getprotos, so you can inspect the strings, numbers, and inner functions the script actually runs - none of which the globals table holds.