getscripthash

Gets a hash of a script's bytecode.

Syntax

getscripthash(script: CoreScript | LocalScript | ModuleScript | Script) -> string?

Parameters

ParameterTypeDescription
scriptCoreScript, LocalScript, ModuleScript, or client ScriptThe script

Returns

TypeDescription
string?A lowercase SHA-384 hexadecimal hash, or nil if the script has no bytecode

Description

getscripthash returns a lowercase SHA-384 hexadecimal hash. It returns nil when bytecode is unavailable.

Example

local module = getloadedmodules()[1]
if module then
    local hash = getscripthash(module)
    print("Script hash:", hash)
end

Comparing Scripts

local function sameCode(script1, script2)
    local first = getscripthash(script1)
    local second = getscripthash(script2)
    return first ~= nil and first == second
end

Tracking Changes

local scriptHashes = {}

local function hasScriptChanged(script)
    local currentHash = getscripthash(script)
    if not currentHash then
        return false
    end
    local previousHash = scriptHashes[script]

    scriptHashes[script] = currentHash

    return previousHash ~= nil and previousHash ~= currentHash
end