Environment

Reach the global environments of Lynx, Roblox and running scripts.

7 functionssUNC 100%Lynx 0.0.0

Every Luau script has an environment: the table its globals live in. Lynx gives you access to its own, to Roblox's, and to the environment of any running script.

Global environments

getgenv

since 1.0.0
getgenv(): table

Returns the Lynx global environment. It's shared by every script you execute: define something there and your next script can use it. Game scripts can't see it.

Returns

table

The Lynx global environment.

Example

getgenv().greet = function(name)
print("Hello,", name)
end
-- In a later script:
greet("world") --> Hello, world

getrenv

since 1.0.0
getrenv(): table

Returns the Roblox global environment, the one game scripts share. Changes here are visible to every game script.

Returns

table

The Roblox global environment.

Example

local renv = getrenv()
print(renv.game == game) --> true
print(renv.getgenv) --> nil
print(typeof(renv._G)) --> table

getsenv

since 1.0.0
getsenv(script: LocalScript | ModuleScript): table

Returns the environment of a running script: its globals, including functions it defined without local. Errors if the script isn't running.

Parameters

scriptLocalScript | ModuleScript
A script that is currently running.

Returns

table

The script's environment.

Example

local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local env = getsenv(character:WaitForChild("Animate"))
for name, value in env do
if typeof(value) == "function" then
print(name)
end
end

Registry and garbage collector

getreg

since 1.0.0
getreg(): table

Returns the Luau registry, the internal table Roblox uses to keep threads, connections and callbacks alive. Most useful for finding threads.

Returns

table

The registry.

Example

local threads = 0
for _, value in getreg() do
if type(value) == "thread" then
threads += 1
end
end
print("threads in the registry:", threads)

getgc

since 1.0.0
getgc(includeTables: boolean?): {any}

Returns every function and userdata the garbage collector is tracking, plus tables when includeTables is true. The result can hold hundreds of thousands of values in large games, so filter early.

Parameters

includeTablesboolean?
Optional.Include tables in the result. Default false.

Returns

{any}

An array of collectable values.

Example

-- Find functions defined in the CameraModule.
for _, value in getgc() do
if type(value) == "function" and islclosure(value) then
local source = debug.info(value, "s")
if source:find("CameraModule", 1, true) then
print(debug.info(value, "n"), debug.info(value, "l"))
end
end
end

Scripts

getloadedmodules

since 1.0.0
getloadedmodules(): {ModuleScript}

Returns every ModuleScript that has been required on the client.

Returns

{ModuleScript}

Loaded modules.

Example

for _, module in getloadedmodules() do
print(module:GetFullName())
end

getrunningscripts

since 1.0.0
getrunningscripts(): {BaseScript}

Returns every script currently running on the client: LocalScripts, client-side Scripts and loaded ModuleScripts.

Returns

{BaseScript}

Running scripts.

Example

local byClass = {}
for _, script in getrunningscripts() do
byClass[script.ClassName] = (byClass[script.ClassName] or 0) + 1
end
print(byClass)