getmenv Synchronous

Read the environment of a loaded ModuleScript. Use it when inspecting a module’s execution context; it is separate from getsenv for ordinary scripts.

Syntax
Luau
getmenv(moduleScript: ModuleScript) -> Table

Parameters

Function parameters
ParameterTypeDescription
moduleScriptModuleScriptLoaded ModuleScript whose environment is needed.

Returns

Table

The ModuleScript environment table.

Usage notes

A ModuleScript with no available running module thread raises an error. Check getloadedmodules first and handle a race where the environment still cannot be read.

Example

Example
Luau
local module = getloadedmodules()[1]
if module then
    local ok, environment = pcall(getmenv, module)
    print(ok and type(environment) or "Environment unavailable")
end
Kawaii documentation