attempt to modify a readonly tablein Roblox Luau: what it means and how to fix it
What it means
You tried to add or change a field on a table that has been locked. Tables locked with table.freeze, and built-in libraries such as math and string, cannot be changed.
The smallest script that triggers it
local Config = table.freeze({ Speed = 16 })
Config.Speed = 20
The fix
local Config = table.freeze({ Speed = 16 })
local settings = table.clone(Config)
settings.Speed = 20
table.clone makes an unlocked copy, so you can change the copy and the frozen original stays as it was.
Common causes
- The table was passed to table.freeze, here or in a module you required.
- The code assigns to a built-in library, for example `math.pi = 3`.
- A typo assigns to a library table when a local variable was meant.
Practice this until it sticks
A Deep Dive on tables, freeze and clone: 5-minute lessons, each with a quiz. What you miss comes back in the next module. One Deep Dive a day is free. No card.