Skip to content

setreadonly

setreadonly sets whether a table is readonly or writable.

function setreadonly(table: { any }, state: boolean): ()

Parameters

Parameter Description
table The table whose readonly status you want to modify.
state true to lock the table, false to unlock it.

Example

Unlocking a metatable
1
2
3
4
5
6
7
8
local mt = getrawmetatable(game)
mt.Example = "Hello" -- Throws an error

setreadonly(mt, false)
mt.Example = "Hello"
print(mt.Example) -- Output: Hello

setreadonly(mt, true) -- Lock back