> ## Documentation Index
> Fetch the complete documentation index at: https://docs.projectreal.gg/llms.txt
> Use this file to discover all available pages before exploring further.

# getmenv

> Returns the environment table associated with a ModuleScript. The argument must be a ModuleScript object. Invalid objects raise "Invalid Instance", non-ModuleScript objects raise "ModuleScript expected", and ModuleScripts without an available thread raise "invalid thread". The function does not accept Script or LocalScript; use getsenv for those cases.

Returns the environment table associated with a ModuleScript. The argument must be a ModuleScript object. Invalid objects raise "Invalid Instance", non-ModuleScript objects raise "ModuleScript expected", and ModuleScripts without an available thread raise "invalid thread". The function does not accept Script or LocalScript; use getsenv for those cases.

## Syntax

```lua theme={null}
getmenv(moduleScript: userdata): table
```

## Arguments

| Name           | Type       | Required | Description                                                     |
| -------------- | ---------- | -------- | --------------------------------------------------------------- |
| `moduleScript` | `userdata` | Yes      | ModuleScript object whose environment table should be returned. |

## Returns

| Name          | Type    | Description                                         |
| ------------- | ------- | --------------------------------------------------- |
| `environment` | `table` | Environment table associated with the ModuleScript. |

## Example

Read the environment table associated with a ModuleScript.

```lua theme={null}
local moduleScript

for _, descendant in ipairs(game:GetDescendants()) do
    if descendant:IsA("ModuleScript") then
        moduleScript = descendant
        break
    end
end

if moduleScript then
    local environment = getmenv(moduleScript)
    print(environment)
end
```
