US Trends

how to freeze a value in dex on roblox

In Roblox/Luau, “freezing a value” usually means making it immutable, and the simplest built-in way is table.freeze() on a table. That prevents edits to the table itself, while a separate pattern is needed if you want only one field or index to stay locked.

Immutable table

If you want the whole table to stop changing:

lua

local data = { coins = 100, level = 5 }
table.freeze(data)

data.coins = 200 -- error

Roblox DevForum examples note that table.freeze exists in Luau and is used to enforce immutability.

Freeze one value

If you only want one value or key to stay fixed, use a metatable or proxy table instead of freezing the whole table. A common approach is to store the real data in a hidden table and block changes to specific keys in __newindex.

lua

local locked = { coins = 100 }
local protected = {}

setmetatable(protected, {
	__index = locked,
	__newindex = function(_, key, value)
		if key == "coins" then
			error("coins is frozen")
		end
		locked[key] = value
	end
})

print(protected.coins) -- 100
protected.coins = 200 -- error

In Dex

If you mean Dex Explorer, you can inspect values, but you generally cannot “freeze” a live game value from Dex alone unless the script itself is designed to prevent changes. In other words, Dex can help you find the object or value, but the freezing behavior must come from the game’s code or a Luau pattern like table.freeze or a locked metatable.

Best practice

  • Use table.freeze() for full-table immutability.
  • Use a metatable proxy for freezing one field.
  • Use WalkSpeed = 0, JumpPower = 0, or anchoring if you mean freezing a character in Roblox gameplay, which is a different thing from freezing a value.

A practical example: if you want a shop price to stay unchanged, freeze the config table; if you want only price to be locked while other fields can update, block that one key with a metatable.