debug.setconstant

Changes a function constant.

Syntax

Signature
debug.setconstant(FunctionOrLevel: function | number, Index: number, Value: any) -> ()

Aliases

This function has no aliases.

Parameters

ParameterTypeDescription
FunctionOrLevelfunction | numberLuau closure or positive stack level.
IndexnumberOne-based constant slot.
ValueanyReplacement with the same type as the existing constant.

Returns

TypeDescription
()None.

Notes

The replacement must have the same VM type as the old value. Table and function constants, and replacements with another type, are left unchanged. An invalid index raises an error.

Example

Luau
local Function = function() return "before" end
for Index, Value in debug.getconstants(Function) do
    if Value == "before" then
        debug.setconstant(Function, Index, "after")
    end
end
print(Function())