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

# getscriptfromclosure

```luau theme={null}
getscriptfromclosure(func: function): LuaSourceContainer?
```

Returns the script instance that defined the given Lua closure function.

## Parameters

| Parameter | Type       | Description                    |
| --------- | ---------- | ------------------------------ |
| `func`    | `function` | The closure function to check. |

## Returns

`LuaSourceContainer?` - The LocalScript or ModuleScript that created the closure, or `nil` if the closure is a C function or has no associated script.

## Example

<CodeGroup>
  ```luau Example 1 theme={null}
  local script = getscriptfromclosure(print)
  ```

  ```luau Example 2 theme={null}
  -- Determine if a function belongs to a game script
  local function check_closure(func)
      local s = getscriptfromclosure(func)
      if s then
          print("Function defined in: " .. s.Name)
      else
          print("Native or untracked function")
      end
  end
  ```
</CodeGroup>

<Tip>
  Handy when hooking functions to identify which game script is invoking specific handlers.
</Tip>
