Scripts
Decompile scripts, read their bytecode and create closures from them.
The Scripts API finds loaded modules, retrieves script environments and bytecode, and decompiles client-available code. Cached script objects, loaded modules, and scripts with live coroutines are separate collections.
Scripts and environments
getcallingscript
getcallingscript(): LuaSourceContainer?getcallingscript returns the source script associated with the calling coroutine.
Also available as get_calling_script, getscriptcaller and getcaller.
Returns
LuaSourceContainer?The calling coroutine’s source script, or nil.
getloadedmodules
getloadedmodules(excludeCore: boolean?): {ModuleScript}getloadedmodules returns the ModuleScripts loaded by the client.
Parameters
excludeCoreboolean??- Optional.Whether to omit descendants of CoreGui and CorePackages. Default
true.
Returns
{ModuleScript}An array of live loaded ModuleScripts.
getrunningscripts
getrunningscripts(): {LuaSourceContainer}getrunningscripts returns the scripts associated with live Lua coroutines in the current VM.
Returns
{LuaSourceContainer}An array of unique scripts associated with live coroutines.
getscriptfromthread
getscriptfromthread(thread: thread): LuaSourceContainer?getscriptfromthread returns the source script associated with a coroutine.
Parameters
threadthread- The coroutine whose source script is requested.
Returns
LuaSourceContainer?The coroutine’s source script, or nil.
getscriptthread
getscriptthread(script: LocalScript | Script | ModuleScript): thread?getscriptthread returns a live coroutine associated with a script in the current VM.
Parameters
scriptLocalScript | Script | ModuleScript- The script whose coroutine is requested.
Returns
thread?An associated live coroutine, or nil when none is found.
getscriptbytecode
getscriptbytecode(script: LuaSourceContainer): string?getscriptbytecode returns the compiled bytecode stored for a client-available script.
Also available as get_scriptbytecode, get_script_bytecode, dumpstring and dump_string.
Parameters
scriptLuaSourceContainer- The script object to inspect.
Returns
string?Decompressed bytecode, or nil when unavailable.
dumpbytecode
dumpbytecode(target: LuaSourceContainer | function): string?dumpbytecode returns the bytecode of a script or serializes a Luau function to bytecode.
Parameters
targetLuaSourceContainer | function- A script object or Luau function to inspect.
Returns
string?Bytecode, or nil when it is unavailable or cannot be serialized.
getscripthash
getscripthash(script: LuaSourceContainer): string | LuaSourceContainer?getscripthash returns a SHA-384 hash of a script’s decompressed bytecode.
Also available as get_scripthash and get_script_hash.
Parameters
scriptLuaSourceContainer- The script object to inspect.
Returns
string | LuaSourceContainer?For the documented single-argument call: the lowercase hexadecimal SHA-384 digest, nil when bytecode is unavailable, or the script argument if stored bytecode cannot be decoded.
getscriptclosure
getscriptclosure(script: LuaSourceContainer): function | LuaSourceContainer?getscriptclosure creates a Luau function from a script’s compiled bytecode without executing it.
Also available as getscriptfunction and get_script_function.
Parameters
scriptLuaSourceContainer- The script object to inspect.
Returns
function | LuaSourceContainer?For the documented single-argument call: a newly loaded Luau function, nil when bytecode is missing or loading fails, or the script argument if stored bytecode cannot be decoded.
getsenv
getsenv(script: LocalScript | Script | ModuleScript | AuroraScript): {[any]: any}?getsenv returns the global environment of a live coroutine associated with the requested script.
Also available as get_senv, getmenv and get_menv.
Parameters
scriptLocalScript | Script | ModuleScript | AuroraScript- The script object to inspect.
Returns
{[any]: any}?The matching coroutine’s global environment, or nil.
decompile
Yieldsdecompile(target: LuaSourceContainer | function | string, options: DecompilerOptions?): stringdecompile converts a script, Luau function, or bytecode string into readable Luau source.
Parameters
targetLuaSourceContainer | function | string- A script object, Luau function, or raw compiled bytecode string.
optionsDecompilerOptions??- Optional.DecompilerOptions controlling recovery and source formatting.
Returns
stringRecovered Luau source. Decompilation failures raise an error.
Example
Decompiler option constructors
DecompilerOptions.new
DecompilerOptions.new(): DecompilerOptionsDecompilerOptions.new creates a mutable options table using the decompiler defaults.
Returns
DecompilerOptionsA new options table with a nested, mutable Formatter table.
Example
DecompilerFormatter.new
DecompilerFormatter.new(): DecompilerFormatterDecompilerFormatter.new creates a mutable formatter table using the decompiler style defaults.
Returns
DecompilerFormatterA new formatter table to assign to an options table's Formatter field.
Example
SmartVariableRenamertrueInferDescriptiveLocalsFunctionDeclarationstruePreferNamedFunctionSyntaxGuardClausestrueFlattenTerminalBranchesEvaluateStaticStringstrueEvaluateStaticStringsDoBlockInsertionThreshold150LocalLifetimeScopeThresholdFormatterIndentWidth4IndentSizeColumnLimit100PreferredLineWidthParenthesizeConditionsfalseStyleWrapConditionsAppendSemicolonsfalseStyleTerminateStatementsFunctionMetadataEnabledtrueStyleFunctionAnnotationsFunctionMetadataLayout0AnnotationPlacementFunctionMetadataIncludeNametrueStyleAnnotateFunctionNamesFunctionMetadataIncludeLinetrueStyleAnnotateSourceLinesFunctionMetadataIncludeUpvaluestrueStyleAnnotateCapturedValuesFunctionMetadataUpvalueFormat0CaptureDetailDecompilerFormatter.FunctionMetadata.Layout.Inline is 0 and .Block is 1. DecompilerFormatter.FunctionMetadata.UpvalueFormat.Name is 1 and .Kind is 0. UseTabs is an additional alias for StyleUseTabs. These enum tables are read-only.
DecompilerOptions
Names are case-insensitive. decompile accepts fields directly or under DecompilerOptions; nested fields are applied after direct ones. Formatter fields may also be supplied in a nested Formatter table; do not provide multiple aliases for the same setting because their iteration order has no guaranteed precedence. saveinstance reads these options only from its DecompilerOptions table, apart from its top-level KeepUnusedLocals field. Unknown keys are ignored. KeepUnusedLocals defaults to true; omitted fields otherwise retain the decompiler library defaults. Boolean fields reject non-booleans and integer fields require a finite integer in the listed range.
Written for Lynx 0.747
Something unclear? Tell us on Discord