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

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

  ## Aliaslar

  * `getscriptfunction`

  ## Argümanlar

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

  ## Dönüşler

  <ResponseField name={"closure"} type={"function | nil"}>
    Loaded Lua closure, or nil when no usable bytecode is available or the Luau loader fails.
  </ResponseField>

  ## Örnek

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