> ## 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.

# getsenv

> Returns the environment table associated with a LocalScript, Script, or ModuleScript. Unsupported script objects or scripts without an available thread raise the same errors as the underlying script lookup.

Returns the environment table associated with a LocalScript, Script, or ModuleScript. Unsupported script objects or scripts without an available thread raise the same errors as the underlying script lookup.

## Syntax

```lua theme={null}
getsenv(script: userdata): table
```

## Arguments

| Name     | Type       | Required | Description                                                                                     |
| -------- | ---------- | -------- | ----------------------------------------------------------------------------------------------- |
| `script` | `userdata` | Yes      | Script object to inspect. Supported ClassName values are LocalScript, Script, and ModuleScript. |

## Returns

| Name          | Type    | Description                                             |
| ------------- | ------- | ------------------------------------------------------- |
| `environment` | `table` | Environment table associated with the script or module. |

## Example

Read the environment table associated with a supported script Instance.

```lua theme={null}
local targetScript

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

if targetScript then
    local environment = getsenv(targetScript)
    print(environment)
end
```
