You already know how to ask one yes-or-no question with if. Now you get to ask two or three at once. Real game rules are almost never about a single condition. “Can the player open this door?” really means “do they have the key AND is the door actually locked?” That is two questions joined into one rule.
Three little words do all the joining: and, or, and not.
andis strict: the whole thing is true only when both sides are true.oris generous: the whole thing is true when at least one side is true.notis a flipper: it turns true into false and false into true.
local hasKey = true
local doorLocked = true
if hasKey and doorLocked then
print("Door unlocked")
else
print("Stay out")
end
Read that if line out loud like a sentence: “if has key and door locked.” Because both hasKey and doorLocked are true, the whole condition is true, so you get Door unlocked. Flip either one to false and and fails the test, so you fall to the else and print Stay out.
Here is the why behind each word. Use and when every condition has to pass, like “logged in AND has enough Studs.” Use or when any one passing is enough, like “is admin OR is the owner.” Use not to read cleaner, so if not isReady then says “if it is NOT ready” instead of forcing you to write == false. You can even mix them, and parentheses keep the grouping clear: if (hasKey or isAdmin) and not isBanned then.
Now make it yours: print the exact Door unlocked line for this lesson, then invent your own two-part rule. Maybe a chest only opens if the player hasKey and not isTrapped, or a boss only spawns if playerCount >= 2 or testingMode. Say your rule out loud first, then write the if to match.