Scripts

Decompile scripts, read their bytecode and create closures from them.

13 functionssUNC 100%Lynx 0.747

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

Yields
decompile(target: LuaSourceContainer | function | string, options: DecompilerOptions?): string

decompile 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

string

Recovered Luau source. Decompilation failures raise an error.

Example

local modules = getloadedmodules()
if modules[1] then
local source = decompile(modules[1], {KeepUnusedLocals = true, IndentSize = 4})
print(source)
end

Decompiler option constructors

DecompilerOptions.new

DecompilerOptions.new(): DecompilerOptions

DecompilerOptions.new creates a mutable options table using the decompiler defaults.

Returns

DecompilerOptions

A new options table with a nested, mutable Formatter table.

Example

local options = DecompilerOptions.new()
options.SmartVariableRenamer = true
options.Formatter.IndentWidth = 2
print(decompile(script, options))

DecompilerFormatter.new

DecompilerFormatter.new(): DecompilerFormatter

DecompilerFormatter.new creates a mutable formatter table using the decompiler style defaults.

Returns

DecompilerFormatter

A new formatter table to assign to an options table's Formatter field.

Example

local options = DecompilerOptions.new()
options.Formatter = DecompilerFormatter.new()
options.Formatter.IndentWidth = 2
print(decompile(script, options))
SmartVariableRenamer
Defaulttrue
InferDescriptiveLocals
FunctionDeclarations
Defaulttrue
PreferNamedFunctionSyntax
GuardClauses
Defaulttrue
FlattenTerminalBranches
EvaluateStaticStrings
Defaulttrue
EvaluateStaticStrings
DoBlockInsertionThreshold
Default150
LocalLifetimeScopeThreshold
Formatter
Defaultnew formatter table
Nested formatting fields
IndentWidth
Default4
IndentSize
ColumnLimit
Default100
PreferredLineWidth
ParenthesizeConditions
Defaultfalse
StyleWrapConditions
AppendSemicolons
Defaultfalse
StyleTerminateStatements
FunctionMetadataEnabled
Defaulttrue
StyleFunctionAnnotations
FunctionMetadataLayout
Default0
AnnotationPlacement
FunctionMetadataIncludeName
Defaulttrue
StyleAnnotateFunctionNames
FunctionMetadataIncludeLine
Defaulttrue
StyleAnnotateSourceLines
FunctionMetadataIncludeUpvalues
Defaulttrue
StyleAnnotateCapturedValues
FunctionMetadataUpvalueFormat
Default0
CaptureDetail

DecompilerFormatter.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.

UseDebugSymbols
Typeboolean
Enables/disables available debug names.
RestoreTypeHints
Typeboolean
Enables/disables recovered type hints.
RestoreTemplateStrings
Typeboolean
Enables/disables template-string recovery.
SeparateLogicalSections
Typeboolean
Enables/disables logical section spacing.
AlignToOriginalLines
Typeboolean
Enables/disables original source-line alignment.
InferDescriptiveLocals
Typeboolean
Enables/disables descriptive local inference.
PreferNamedFunctionSyntax
Typeboolean
Enables/disables named function declaration syntax.
FlattenTerminalBranches
Typeboolean
Enables/disables terminal branch flattening.
EvaluateStaticStrings
Typeboolean
Enables/disables static string evaluation.
RecoverCompoundAssignments
Typeboolean
Enables/disables compound assignment recovery.
AggressiveNames
Typeboolean
Enables/disables aggressive name inference.
KeepUnusedLocals
Typeboolean
Enables/disables preservation of unused locals.
StyleUseTabs
Typeboolean
Enables/disables tab indentation.
StyleWrapConditions
Typeboolean
Enables/disables condition wrapping.
StyleTerminateStatements
Typeboolean
Enables/disables statement terminators.
StyleFinalNewline
Typeboolean
Enables/disables a final newline.
StyleFunctionAnnotations
Typeboolean
Enables/disables function annotations.
StyleCRLF
Typeboolean
Enables/disables CRLF line endings.
StyleAnnotateFunctionNames
Typeboolean
Enables/disables function-name annotations.
StyleAnnotateSourceLines
Typeboolean
Enables/disables source-line annotations.
StyleAnnotateCapturedValues
Typeboolean
Enables/disables captured-value annotations.
LocalLifetimeScopeThreshold
Accepted range0–1,000,000
Local-lifetime scope threshold.
IndentSize
Accepted range0–16
Indentation width.
PreferredLineWidth
Accepted range20–1,000
Preferred output line width.
TableLayout
Accepted range0–2
0 = auto, 1 = compact, 2 = expanded.
TrailingCommas
Accepted range0–1
0 = never, 1 = multiline tables.
TableBraces
Accepted range0–2
0 = tight, 1 = pad nonempty tables, 2 = always pad.
StringQuotes
Accepted range0–2
0 = double quotes, 1 = single quotes, 2 = auto.
ElseifLayout
Accepted range0–1
0 = collapsed elseif, 1 = nested branches.
AnnotationPlacement
Accepted range0–1
0 = inline, 1 = separate lines.
CaptureDetail
Accepted range0–1
0 = names with capture kind, 1 = names only.
ArgumentLayout
Accepted range0–2
0 = auto, 1 = compact, 2 = expanded.
MaximumInlineArguments
Accepted range0–128
Maximum arguments eligible for inline layout.
VectorTypeName
Accepted valuestring, 0–63 bytes
The name to use in recovered source. Embedded NUL characters are not allowed.
VectorLibraryName
Accepted valuestring, 0–63 bytes
The name to use in recovered source. Embedded NUL characters are not allowed.
VectorConstructorName
Accepted valuestring, 0–63 bytes
The name to use in recovered source. Embedded NUL characters are not allowed.
ModuleSuffix
Accepted valuestring, 0–63 bytes
The name to use in recovered source. Embedded NUL characters are not allowed.