Make your scripts decide things — check a condition, and run different code depending on the answer.
Your scripts can count coins now. But a game needs judgment: if the player has enough coins, let them buy; if they touch a spike, they take damage; if they've won, celebrate. That judgment is conditionals, and they're how scripts make decisions.
if coins >= 50 then
print("Enough coins!")
end
Read it as: "if it's true that coins is 50 or more, run the lines inside — otherwise skip them." The lines inside only run when the condition is true.
A condition is just an expression that produces a boolean — true or false. You met booleans already; this is where they earn their keep.
local x = 10
if x > 5 then
print("big")
else
print("small")
end
if coins >= 100 then
print("Whale! Splurge on the deluxe pack.")
elseif coins >= 50 then
print("Decent. You can afford the basic pack.")
else
print("Keep grinding — not enough yet.")
end
Luau checks top to bottom: first if, then each elseif, and if none matched, it runs else. Only one branch ever runs. elseif and else are optional — a lone if is fine.
When does the else branch run?
What if a sale needs two things to be true — enough coins and a membership?
if coins >= 50 and hasMembership then
print("Welcome to the members shop.")
end
and — both sides must be true.or — at least one side true.You can chain them: if a and b or c then. Add parentheses when it gets complicated: if (a and b) or c then.
A prize is given when the player's score is at least 100 OR they found the golden key. Write the if-line condition.
local score = 90
local hasGoldenKey = true
-- your if line here
= inside an if. if coins = 50 errors. Compare with ==.and and or. if a and b needs both. if a or b needs one. When in doubt, read it out loud.if coins >= 0 is true for every non-negative number. If you meant exactly zero, write == 0.Next: doing something over and over — loops.