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

# decompile

> Decompiles a Roblox script and returns the generated source text when bytecode is available. The argument must be a supported script Instance. If usable bytecode is not available, the function returns nil.

Decompiles a Roblox script and returns the generated source text when bytecode is available. The argument must be a supported script Instance. If usable bytecode is not available, the function returns nil.

## Syntax

```lua theme={null}
decompile(script: userdata): string | nil
```

## Arguments

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

## Returns

| Name     | Type            | Description                                                                                                       |
| -------- | --------------- | ----------------------------------------------------------------------------------------------------------------- |
| `source` | `string \| nil` | Decompiler output string, caught decompiler exception text, or nil when no usable embedded bytecode is available. |

## Example

Decompile a supported Roblox script Instance. To decompile a whole game, iterate its descendants or use a saveinstance workflow.

```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 source = decompile(targetScript)

    if source then
        print(source)
    end
end
```
