ReferenceMetatables

setreadonly

Makes a table read-only or writable.

Syntax

setreadonly(target: table, readonly: boolean) -> ()

Also available as

set_read_only

Parameters

ParameterTypeDescription
targettableThe table to change.
readonlybooleantrue to freeze the table, false to allow writes again.

Description

Luau tables can be frozen; writing to a frozen table raises attempt to modify a readonly table. table.freeze can only freeze. setreadonly can also unfreeze, which is what you need to edit a frozen table such as an Instance metatable or a frozen module table.

Example

local mt = getrawmetatable(game)
setreadonly(mt, false)
local index = mt.__index
mt.__index = newcclosure(function(self, key)
    return index(self, key)
end)
setreadonly(mt, true)

Notes

These are Game executor contracts. Check build requirements and session lifetimes before using them.