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

# getscriptclosure

> Loads the stored bytecode for a supported Roblox script Instance and returns it as a Lua closure. Returns nil when usable bytecode is not available.

Loads the stored bytecode for a supported Roblox script Instance and returns it as a Lua closure. Returns nil when usable bytecode is not available.

## Syntax

```lua theme={null}
getscriptclosure(script: userdata): function | nil
```

## Aliases

* `getscriptfunction`

## Arguments

| Name     | Type       | Required | Description                                                                                                                     |
| -------- | ---------- | -------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `script` | `userdata` | Yes      | Script object to load. Supported ClassName values are ModuleScript, LocalScript, CoreScript, and Script with RunContext Client. |

## Returns

| Name      | Type              | Description                                                                               |
| --------- | ----------------- | ----------------------------------------------------------------------------------------- |
| `closure` | `function \| nil` | Loaded Lua closure, or nil when no usable bytecode is available or the Luau loader fails. |

## Example

Load a function from a supported Roblox script Instance when bytecode is available.

```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 closure = getscriptclosure(targetScript)
    print(closure)
end
```
