Add, subtract, multiply, divide, and find remainders — the arithmetic your game does a thousand times a day.
Games are math happening fast enough to look like a game. Every coin pickup, damage tick, and score multiplier is just arithmetic. Let's make it second nature.
| Operator | Does | Example |
|---|---|---|
+ | add | 10 + 5 → 15 |
- | subtract | 10 - 5 → 5 |
* | multiply | 10 * 5 → 50 |
/ | divide | 10 / 5 → 2 |
% | remainder | 10 % 3 → 1 |
That last one, %, gives you what's left over after division. 10 % 3 is 1 because 3 goes into 10 three times with 1 left. Remainders are how games tell even from odd, and how timers detect "every 5th tick".
Compute 7 % 3. Fill in the result: print(7 % 3) -->
You already saw the counting pattern — now it takes multipliers:
local score = 100
score = score + 10 --> 110
score = score * 2 --> 220
score = score - 50 --> 170
score = score / 2 --> 85
Each line reads the box, does math, and stores the result back. That's how you build a double-score power-up or a speed boost: multiply the box.
Luau also has the shorthand versions +=, -=, *=, /=. score += 10 is exactly score = score + 10. Both are fine — pick one and be consistent.
Math follows the usual rules: multiplication and division happen before addition and subtraction.
print(2 + 3 * 4) --> 14, not 20
3 * 4 runs first, then the +. When you want to override the order, use parentheses:
print((2 + 3) * 4) --> 20
A player earned 5 coins, then the game doubles everyone's total. Start a coins box at 0, add 5, then double it.
-- your three lines here