getscriptclosure
Builds a callable function from a script's bytecode.
Syntax
getscriptclosure(script: LuaSourceContainer) -> function
Also available as
getscriptfunctionget_script_closureget_script_function
Parameters
| Parameter | Type | Description |
|---|---|---|
script | LuaSourceContainer | A LocalScript, Script or ModuleScript. |
Returns
| Type | Description |
|---|---|
function | A new function made from the script's bytecode. |
Description
The function is a fresh copy of the script's main chunk. Each closure has a fresh environment that inherits your globals and sets script to the requested instance. Calling it runs the script's code again in that environment, which is useful for reading a module's return value without require or for inspecting the constants and nested functions of a script that has not run. Each call returns a new function.
Example
local module = game.ReplicatedStorage.Config
local chunk = getscriptclosure(module)
print(getconstants(chunk))
local config = chunk()
Notes
- Missing bytecode raises an error; bytecode that fails to load returns the error message as a string.
These are Game executor contracts. Check build requirements and session lifetimes before using them.
