World Executor · Roblox VM

Environment

Reach into the global environments that scripts run in, inspect what the garbage collector holds, and walk every live thread.

Overview

There are several global tables in play at once and they are not the same table. Getting them mixed up is the single most common source of "it works in the editor but not from autoexec".

  • getgenv() — the executor's shared global environment. Persists between executions. Put your own state here.
  • getrenv() — Roblox's own global environment, the one game scripts see. Changing it changes the game.
  • gettenv(thread) — the globals of one specific thread.
  • getreg() — the raw Luau registry.
Which global table is which
-- Load-once guard, the idiomatic way.
if getgenv().__mytool then
    return warn("already loaded")
end
getgenv().__mytool = true

-- Reach into the game's own globals.
local renv = getrenv()
print(renv.game == game)     --> true

getgc and filtergc walk everything the garbage collector is holding, which is how you find a table or function nothing has handed you a reference to.

Finding a table with filtergc
-- Find the game's own config table by its shape.
local matches = filtergc("table", {
    Keys = { "WalkSpeed", "JumpPower" },
}, false)

for _, found in ipairs(matches) do
    print(found.WalkSpeed, found.JumpPower)
end

Global environments

Garbage collector

Threads