Const
A value that must not change should say so. In C++ that is const. Cluaupp emits Luau const, not local x <const>.
const int STARTING_COINS = 0;const double GRAVITY = 196.2;const STARTING_COINS: number = 0const GRAVITY: number = 196.2Why it is a safety feature
Section titled “Why it is a safety feature”- Leaderstat starting values, product IDs, remote names, and animation speeds are configuration. If they are
local, a later line can overwrite them by accident. - Reviewers see
constand skip “could this mutate?”. - Luau
--!strictrejects assignment toconst.
What to keep mutable
Section titled “What to keep mutable”Player-owned numbers (coins, combo), UI state, and Janitor instances. Everything else defaults to const until you have a reason.
const string REMOTE_COINS = "Coins";int coins = 0;
void AddCoins(int amount) { coins = coins + amount;}REMOTE_COINS is a protocol name — immutable. coins is session state — mutable.
Immutability for tables and Instances
Section titled “Immutability for tables and Instances”const on a pointer does not freeze the Instance. const Folder stats still has a mutable Name in Roblox. Treat “do not rebind the variable” and “do not mutate the object” as two separate decisions. For objects, prefer:
- Create, parent, configure once, then only read.
- Put mutations behind one function (
SetCoins) instead of writingcoins.Valuefrom five scripts.
DataService paths
Section titled “DataService paths”Path tokens ("Currencies.Coins") should be const string or a shared header. Never concatenate remote or datastore keys from user input.
Next: safety.