Environment

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

Overview

There are a few different global tables and they're not the same table. Mixing them up is the most common reason for "it works in the editor but not in autoexec".

  • getgenv(): the executor's shared globals. Sticks around between executions. Put your own stuff here.
  • getrenv(): Roblox's own globals, the ones 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 go through everything the garbage collector is holding, so you can find a table or function nobody gave 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