Published Sep 1, 2023Updated Mar 2, 2024
Contribute to Docs

The .freeze() function in Luau freezes the provided table and makes it read-only.



The .freeze() function attempts to freeze a specified non-frozen table named f. The function willย fail if fย is not a table or is already frozen.


Consider the following table:

local frozen_table = table.freeze({

The variable frozen_table is instantiated with the .freeze() method to make the contents read-only.

Now, if an element is added:

frozen_table[1] = "๐Ÿ”"

The code will return the following output:

Error: Frozen table cannot be modified

The error is thrown because the method has made the table read-only, so the contents cannot be modified.

All contributors

Looking to contribute?

Learn Luau on Codecademy