ReferenceScripts

getscriptclosure

Builds a callable function from a script's bytecode.

Syntax

getscriptclosure(script: LuaSourceContainer) -> function

Also available as

getscriptfunctionget_script_closureget_script_function

Parameters

ParameterTypeDescription
scriptLuaSourceContainerA LocalScript, Script or ModuleScript.

Returns

TypeDescription
functionA 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

These are Game executor contracts. Check build requirements and session lifetimes before using them.