Scripts

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

4 functionssUNC 100%Lynx 0.0.0

These functions work on any script whose bytecode reached your PC: LocalScripts, ModuleScripts and client-side Scripts. Decompiling scripts explains what never does.

Source

decompile

since 1.0.0Yields
decompile(script: LocalScript | ModuleScript | Script | string): string

Decompiles script and returns Luau source. A string is treated as bytecode, such as the result of getscriptbytecode.

When a script can't be decompiled, the result is a Luau comment that says why instead of an error. Functions aren't accepted.

Parameters

scriptLocalScript | ModuleScript | Script | string
A script with client-side bytecode, or a bytecode string.

Returns

string

The reconstructed source, or a comment with the reason it failed.

Example

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local module = ReplicatedStorage:FindFirstChildWhichIsA("ModuleScript", true)
if module then
print(decompile(module))
end

Bytecode

getscriptbytecode

since 1.0.0
getscriptbytecode(script: LocalScript | ModuleScript | Script): string

Returns the raw Luau bytecode of script as a binary string.

Also available as dumpstring.

Parameters

scriptLocalScript | ModuleScript | Script
A script with client-side bytecode.

Returns

string

The bytecode.

Example

local playerScripts = game:GetService("Players").LocalPlayer.PlayerScripts
local playerModule = playerScripts:WaitForChild("PlayerModule")
local bytecode = getscriptbytecode(playerModule)
print(#bytecode, "bytes")
writefile("PlayerModule.luauc", bytecode)

getscripthash

getscripthash(script: LocalScript | ModuleScript | Script): string

Returns a SHA-384 hash of script's bytecode as a hex string. Two scripts with the same hash are byte-for-byte identical, which makes this a quick way to notice when a game updates a script.

Parameters

scriptLocalScript | ModuleScript | Script
A script with client-side bytecode.

Returns

string

96 hex characters.

Example

local playerScripts = game:GetService("Players").LocalPlayer.PlayerScripts
local playerModule = playerScripts:WaitForChild("PlayerModule")
local hash = getscripthash(playerModule)
if isfile("PlayerModule.hash") and readfile("PlayerModule.hash") ~= hash then
print("PlayerModule changed since last time")
end
writefile("PlayerModule.hash", hash)

getscriptclosure

since 1.0.0
getscriptclosure(script: LocalScript | ModuleScript | Script): function

Creates a new function from script's bytecode: its main chunk, not yet run. Calling it runs a separate copy of the script in your thread, leaving the original untouched.

Also available as getscriptfunction.

Parameters

scriptLocalScript | ModuleScript | Script
A script with client-side bytecode.

Returns

function

The script's main function.

Example

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local module = ReplicatedStorage:WaitForChild("Config")
-- A fresh copy of the module's return value, independent of the game's.
local config = getscriptclosure(module)()
print(config)