getscriptclosure Synchronous

  • getscriptfunction

Create or retrieve a callable closure from a script Instance’s stored code. Use it when you need a function value for inspection rather than raw bytecode text.

Syntax
Luau
getscriptclosure(script: ScriptInstance) -> Function?

Parameters

Function parameters
ParameterTypeDescription
scriptScriptInstanceScript Instance with available stored bytecode.

Returns

Function?

A function, or nil when the script bytecode is unavailable.

Usage notes

Obtaining the closure is separate from calling it. Calling script code can have side effects, so inspect the result before invocation.

Example

Example
Luau
local candidate = getscripts()[1]
if candidate then
    local closure = getscriptclosure(candidate)
    print("Closure available:", type(closure) == "function")
end
Kawaii documentation