Environment

getrenv

Returns the Roblox global environment table.

Syntax

getrenv(): table

Returns

NameTypeDescription
environmenttableThe Roblox global environment table.

Description

Returns the Roblox global environment table. The function takes no arguments and returns exactly one value.

Call it without parameters. The function reads the needed context from the current runtime state.

It returns environment (table). Use the returns table to separate successful values from nil results and recoverable errors.

Example

Read the Roblox global environment table returned by Real.

local robloxEnv = getrenv()

print(type(robloxEnv))
print(rawget(robloxEnv, "_G"))
print(rawget(robloxEnv, "shared"))