---
title: "getsenv"
description: "Finds a matching live thread and returns its globals."
---

```lua
getsenv(script: LocalScript | ModuleScript | Script): table?
```

---

## Aliases

- `getscriptenv`

---

## Arguments

<ParamField body="script" type="LocalScript | ModuleScript | Script" required>
  The script Instance to inspect.
</ParamField>

---

## Returns

<ResponseField name="environment" type="table?">
  The matching script thread's globals, or nil when unavailable.
</ResponseField>

Nil for unsupported classes, no matching thread, or another main VM. A ModuleScript does not necessarily retain a discoverable thread.

**Related types:** [Scripts types & behavior](/reference/scripts/types).

---

## Example

```lua
for _, script in ipairs(getrunningscripts()) do
    local env = getsenv(script)
    if env then print(script.Name, type(env)) break end
end
```
