getrenv
Retrieves the global environment of the Roblox game client.
function getrenv(): tableSynopsis
How it works
Returns the Roblox client's base 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 same
_G that game LocalScripts and ModuleScripts see. This is the environment containing Roblox globals like game, workspace, script, and the standard Luau libraries (math, string, table, etc).Under the hood
The executor walks the Luau VMLuau VMThe Luau Virtual Machine — a register-based bytecode interpreter. Executes compiled Luau instructions sequentially, managing a value stack, call stack, and upvalue chains. Roblox runs one VM per Actor context.'s thread list to find a game-owned
lua_State and returns its gt (global table) pointer. This table is shared by all game scripts, so modifying it affects every LocalScriptLocalScriptA Roblox script type that runs on the client (player's machine). Has access to client-only APIs like UserInputService, Camera, and local player. Executes in the context of the local Player.'s view of globals.Security implications
Writing to
getrenv() is extremely powerful but dangerous:- Overwriting
getrenv().printintercepts all game-side print calls - Adding keys can leak executor presence to anti-cheatAnti-cheatGame-side Luau scripts designed to detect and prevent exploitation. Common checks: verifying closure types (iscclosure), checking metatable integrity, monitoring remote call patterns, and scanning for known executor globals. scripts that enumerate globals
- Deleting keys can break game functionality
hookfunction or hookmetamethod for targeted interception instead of modifying the raw environment.Usage
Inspect native globals
local renv = getrenv()
for k, v in pairs(renv) do
print(k, type(v))
endReturns
table The global environment table of the Roblox client.
Read Carefully
Modifying values in this environment can break the game's native scripts. Always test in a controlled environment.