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

<div className="real-function-page">
  ```lua theme={null}
  getsenv(script: userdata): table
  ```

  ## الوسائط

  <ParamField path={"script"} type={"userdata"} required>
    Script object to inspect. Supported ClassName values are LocalScript, Script, and ModuleScript.
  </ParamField>

  ## القيم الراجعة

  <ResponseField name={"environment"} type={"table"}>
    Environment table associated with the script or module.
  </ResponseField>

  ## مثال

  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
  ```
</div>
