Skip to content

getscriptclosure

Closure is compiled from the script's bytecode, not an active one

The function returned by getscriptclosure is a new closure compiled from the script's bytecode. It is not the function used by the game script, but has identical metadata. This function is usually used to retrieve constants from a script.

Not all scripts have bytecode

If the script has no compiled bytecode, this function will return nil.

getscriptclosure creates and returns a Lua function closure from the compiled bytecode of a Script, LocalScript, or ModuleScript.

This function is often used to extract constants or behaviour from scripts without needing to run them inside the game.

function getscriptclosure(script: BaseScript | ModuleScript): (...any) -> (...any) | nil

Parameters

Parameter Description
script The script instance to convert into a function.

Example

Retrieving a script's closure
1
2
3
4
5
6
7
local animate = game.Players.LocalPlayer.Character:FindFirstChild("Animate")

local closure = getscriptclosure(animate)

print(typeof(closure)) -- Output: function 0x....

print(getscriptclosure(Instance.new("LocalScript"))) -- Output: nil