setreadonly
Makes a table read-only or writable.
Syntax
setreadonly(target: table, readonly: boolean) -> ()
Also available as
set_read_only
Parameters
| Parameter | Type | Description |
|---|---|---|
target | table | The table to change. |
readonly | boolean | true 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
- Put the table back the way you found it when you are done; game code may rely on it staying frozen.
These are Game executor contracts. Check build requirements and session lifetimes before using them.
