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

# getscriptclosure

Returns the <abbr title="The whole script's code, treated as one function. Roblox runs it once when the script loads.">main closure</abbr> of a `LocalScript` or `ModuleScript`, recompiled from the script's bytecode on every call.

```luau theme={null}
getscriptclosure(script: LuaSourceContainer): function
```

Each call recompiles the closure from the script's bytecode.

## Parameters

| Parameter | Type                                                                                               | Description                           |
| --------- | -------------------------------------------------------------------------------------------------- | ------------------------------------- |
| `script`  | [`LuaSourceContainer`](https://create.roblox.com/docs/reference/engine/classes/LuaSourceContainer) | The script to compile a closure from. |

## Returns

`function`

## Aliases

* `getscriptfunction`

## Example

In a game whose shop UI is a `LocalScript`, recover its hardcoded string literals even though Roblox stripped `.Source` on the client.

<CodeGroup>
  ```luau Example 1 theme={null}
  <<<<<<< HEAD
  local closure = getscriptclosure(workspace.Part.LocalScript)
  =======
  -- getscriptclosure(script: LuaSourceContainer): function
  >>>>>>> 50e30f53759b0538759af25c9b271514aa2c9290
  ```

  ```luau Example 2 theme={null}
  local target = game:GetService("Players").LocalPlayer.PlayerScripts:FindFirstChildOfClass("LocalScript")
  local closure = getscriptclosure(target)
  for i, k in ipairs(debug.getconstants(closure)) do
      print(`[{i}] {typeof(k)} {tostring(k)}`)
  end
  ```
</CodeGroup>

<Tip>
  Roblox strips `LocalScript.Source` and `ModuleScript.Source` to empty strings on the client. `getscriptclosure()` paired with `debug.getconstants()` is the way around it - the returned closure carries the script's bytecode, which `debug` reads directly.
</Tip>
