Skip to content

debug.setconstant

C closures are not supported

This function will throw an error if called on a C closure, such as print, since C closures have no accessible constants.

Mutable globals

If gameis a mutable global, the constant indexes will be different.

debug.setconstant modifies a constant at the specified index in a Luau function bytecode.

This can be used to change hardcoded behavior within functions without modifying their source code - although it requires knowing the correct constant index beforehand.

function debug.setconstant(func: (...any) -> (...any) | number, index: number, value: number | string | boolean | nil): ()

Parameters

Parameter Description
func The Lua function (or stack level) whose constant to modify.
index The position of the constant to change.
value The new constant value to set.

Example

Overwriting a constant string in a function
1
2
3
4
5
6
7
local function dummy_function()
    print(game.Name)
end

debug.setconstant(dummy_function, 4, "Players")

dummy_function() -- Output: Players