getgenv
Returns the custom global environment of the executor.
function getgenv(): tableSynopsis
How it works
The executor maintains a separate Luau
lua_State with its own global table (_G). getgenv() returns a reference to this table. All executor scripts share the same global environmentGlobal environment (genv)The executor's global environment table — the _G-equivalent for executor-loaded scripts. Functions set here (via getgenv()) are accessible from any executor script but invisible to game scripts., so writing getgenv().x = 1 in one script makes x available in any subsequent script execution.Memory model
Internally, every Luau thread carries an
env pointer (its global environmentGlobal environment (genv)The executor's global environment table — the _G-equivalent for executor-loaded scripts. Functions set here (via getgenv()) are accessible from any executor script but invisible to game scripts. table). The executor creates a master environment table at injection time and points all executor threads to it. Game scripts point to a completely separate table — the Roblox global environment. This isolation prevents cross-contamination.Relationship to getrenv
getgenv()→ executor's global table (your scripts)getrenv()→ Roblox client's global table (game scripts)- Both are normal Luau tables, but they reference different
lua_Stateenvironments
Usage
Shared variable
getgenv().MySharedLib = {
greet = function(name)
return "Hello, " .. name
end
}
"cc">-- Accessible in any other script:
print(MySharedLib.greet("World")) "cc">-- "Hello, World"Returns
table The global environment table of the executor.