getfenv
Environment get/set for functions, Roblox-style. getfenv() with no usable argument returns the global table; getgenv() always returns it.
Syntax
getfenv(fn?: function) -> table
getgenv() -> table
Parameters
| Parameter | Type | Description |
|---|---|---|
fn? | function | The function or callback to use. |
Returns
| Type | Description |
|---|---|
table | The global table |
Description
getfenv is part of the Scripts & decompiling library. Script helpers inspect scripts in the live DataModel and can read bytecode or decompile source.
The call is read-only: it resolves the current value when invoked and does not change the underlying state.
The aliases setfenv(fn, table) resolve to the same implementation.
getgenv() returns the VM's global table directly and is the usual place for scripts to share values between executions.
Example
local value = 1
local fn = function() return value end
local env = getfenv(fn)
print(env)
setfenv(fn, env)
getgenv().shared = true
print(getgenv().shared)
Notes
- Aliases:
setfenv(fn, table). getgenv()— Always returns the global table, regardless of arguments.- Script bytecode and source are read from the live game.