Variables and scope
int n = 0; // local numberage: int = 10; // same, postfix typeconst int MAX = 10; // Luau constobservable int coins = 100; // IntValue; assign to fire Changedsignal<Player, int> OnPay; // BindableEvent wrapperauto players = GetService<Players>();Where a name lives
Section titled “Where a name lives”- File-level declarations → file
local/const. - Inside a function → from that line to the end of the block. Nested
{ }may shadow. - Inside
Class::Method→@this/thisisself.@fieldand bare field names becomeself.field. Parameters shadow fields.
Globals that stay bare
Section titled “Globals that stay bare”post, warn, report, game, workspace, task, library types, Instance classes, datatypes.
Lifetime
Section titled “Lifetime”Leaving a { } block does not Destroy Instances. Use Janitor, ~>Connect, or an explicit .Destroy().
Destructuring
Section titled “Destructuring”auto [ok, result] = pcall(func () { return 1;});Emits local ok, result = pcall(...).
Next: Functions and callbacks.