Syntax
getscriptclosure(script: userdata): function | nilAliases
getscriptfunctionArguments
| Name | Type | Description |
|---|---|---|
script | userdata | Script object to load. Supported ClassName values are ModuleScript, LocalScript, CoreScript, and Script with RunContext Client. |
Returns
| Name | Type | Description |
|---|---|---|
closure | function | nil | Loaded Lua closure, or nil when no usable bytecode is available or the Luau loader fails. |
Description
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.
Call it with 1 parameter(s): script. The argument table explains which values are required and which ones only refine the behavior.
It returns closure (function | nil). Use the returns table to separate successful values from nil results and recoverable errors.
Example
Load a function from a supported Roblox script Instance when bytecode is available.
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