Decisions, lesson 10
Checkpoint: the gate rule
Goal: Turn a written rule into working conditions.
about 7 min3 practice exercises
Time to put module 2 together. Coin Quest has a gate with three rules:
- A player with a VIP pass always gets in.
- Anyone else needs at least 10 coins.
- If the gate is broken, nobody gets in.
local coins = 12
local isVip = false
local gateBroken = false
if gateBroken then
print("The gate is jammed")
elseif isVip or coins >= 10 then
print("The gate opens")
else
print("You need " .. 10 - coins .. " more coins")
end
The broken check comes first because it beats every other rule. Then one condition covers both ways in.
When you test a rule like this, try the edges: exactly 10 coins, 9 coins, 0 coins, VIP with 0 coins, and a broken gate with a VIP. Bugs live at the edges.
Try it in Studio
Optional, and the best way to make it stick.
Put the gate rule in a Script, then change the three variables at the top to test all five edge cases from the lesson.
Sources
Checked against Roblox's documentation on . The lesson is in our own words; these pages are the source of truth.