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.
Luau
getmenv(moduleScript: ModuleScript) -> TableParameters
| Parameter | Type | Description |
|---|---|---|
moduleScript | ModuleScript | Loaded ModuleScript whose environment is needed. |
Returns
TableThe 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
Luau
local module = getloadedmodules()[1]
if module then
local ok, environment = pcall(getmenv, module)
print(ok and type(environment) or "Environment unavailable")
end