Module 4 · Making decisions
Mini-project: A locked door decision
Combine key state and player level into an ordered door rule with focused messages.
What you will learn
- Implement ordered door conditions
- Give a distinct message for each unmet requirement
- Test public boundary cases
- boundary case
- An input at or beside a rule's limit.
- decision table
- A list of input combinations and intended outcomes.
Loading saved progress…
Understand
Read the idea and follow a worked example.
Why this matters
The first interactive Coin Quest rule should be understandable to both the player and the person reading its code.
The mental model
Check the most fundamental missing requirement first, then the level boundary, then the success path. Each branch owns one explanation.
Test combinations including no key, a level below five, exactly five, and above five.
New words and symbols
--!strict asks Studio to check your code for type mistakes. It is an instruction for the editor and produces no Output message.
Matching quotes such as "hello" surround a string: a piece of text. The quotation marks tell Luau where the text starts and ends.
print(...) calls the built-in print function. Put the values to show inside its parentheses; separate multiple values with commas. Read the result in Studio's Output panel.
local is read as “local”: it creates a name that is available only in the current code scope.
if is read as “if”: it starts a decision by evaluating a condition.
then is read as “then”: it marks the body that can run when the condition is truthy.
elseif is read as “else if”: it checks another condition only after earlier branches did not run.
else is read as “else”: it provides the fallback branch.
end is read as “end”: it closes a block such as a decision, loop, or function.
A tiny example
--!strictlocal hasKey = truelocal playerLevel = 5if not hasKey then print("Find the wooden key")elseif playerLevel < 5 then print("Reach level 5")else print("The door opens")endLine by line
- 3
The key state is one requirement.
- 4
The numeric level is the second.
- 6
The missing-key guard has the first message.
- 8
Only key holders reach the level check.
- 10
The fallback means both requirements passed.
- 11
Success gets a distinct message.
Read the code aloud
Read one statement at a time: name the value being read, what the operation does, and where its result goes. Keep identifiers exactly as written so you can find them again in the code.
Pause at calls, conditions, and loops. Explain when the body runs before moving to the next statement; use the line notes above when a symbol is unfamiliar.
Execution trace
Begin at the first executable statement. Comments and blank lines do not run; a branch chooses which block runs, and a loop may revisit its body.
Line 3: The key state is one requirement.
Line 4: The numeric level is the second.
Line 6: The missing-key guard has the first message.
Line 8: Only key holders reach the level check.
Line 10: The fallback means both requirements passed.
Line 11: Success gets a distinct message.
State before and after
Before running, identify the starting values and any existing Studio objects this example needs. List what you expect to change.
After your practice change, check this result: Every public state reaches one helpful message, including the exact level boundary.
Reading or printing a value leaves it unchanged. Look for assignments, calls that change state, and property updates to explain each change you observe.
Predict before running
What happens with a key at exactly level 5?
Try it
Mark each step after you have tried it.
Common mistake
Checking playerLevel <= 5 would reject a player at exactly the required level. Translate 'at least five' carefully: failure is below five, and success includes five.
Checkpoint
Submit once you have considered every question. Retries are unlimited.
Recap
- Order failure checks deliberately.
- Boundary operators encode the exact rule.
- Each path should give focused feedback.
Next: Module 5 repeats work safely to build Coin Quest round timing.
Studio challenge
A locked door decision
Checks are formative feedback, not cheat-proof certification. You can finish this lesson without the plugin.
- Target
- ServerScriptService/LearningLuau/LockedDoor
- Check mode
- source and output
Challenge state: idle
Studio Companion
Not connected
Connect once. Compatible challenges will prepare automatically as you reach them.