Module 3 · Expressions, operators, and text
Mini-project: Build a score summary
Calculate a final score and format a useful player message.
What you will learn
- Calculate a score from public inputs
- Use a comparison to describe progress
- Format a readable summary
- derived value
- A value calculated from other state.
- public case
- A visible test input and result used for learning feedback.
Loading saved progress…
Understand
Read the idea and follow a worked example.
Why this matters
A score summary turns raw Coin Quest state into feedback a player can understand and gives the Studio Companion a safe calculation to test with public values.
The mental model
First calculate numeric state, then compare it with a goal, then format the result. Keeping those steps separate makes each one testable.
Public runtime cases disclose their inputs and purpose. They provide formative feedback without claiming that the code is certified.
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.
= is read as “is assigned”: it evaluates the right side and stores that value in the name on the left.
A tiny example
--!strictlocal playerName = "Ari"local coins = 7local pointsPerCoin = 10local bonus = 5local finalScore = (coins * pointsPerCoin) + bonuslocal reachedGoal = finalScore >= 50local summary = `{playerName}: {finalScore} points; goal reached: {reachedGoal}`print(summary)Line by line
- 3
The name is display data.
- 4
The collected coin input stays numeric.
- 5
The multiplier is named.
- 6
A separate bonus completes the rule.
- 7
finalScore is a derived numeric value.
- 8
The comparison records goal state.
- 9
Interpolation produces the player-facing summary.
- 11
The finished message is printed.
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 name is display data.
Line 4: The collected coin input stays numeric.
Line 5: The multiplier is named.
Line 6: A separate bonus completes the rule.
Line 7: finalScore is a derived numeric value.
Line 8: The comparison records goal state.
Line 9: Interpolation produces the player-facing summary.
Line 11: The finished message is printed.
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: The formatted message matches each public numeric case and remains readable.
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
Which final score appears for the shown public values?
Try it
Mark each step after you have tried it.
Common mistake
Do not turn the coin count into text before calculating. Keep game state numeric, calculate first, and format at the final display step.
Checkpoint
Submit once you have considered every question. Retries are unlimited.
Recap
- Calculate state before formatting it.
- Comparisons add meaningful status to a summary.
- Public cases make supported behavior checks understandable.
Next: Module 4 uses these boolean expressions to choose which behavior runs.
Studio challenge
Build a score summary
Checks are formative feedback, not cheat-proof certification. You can finish this lesson without the plugin.
- Target
- ServerScriptService/LearningLuau/ScoreSummary
- Check mode
- source and output
Challenge state: idle
Studio Companion
Not connected
Connect once. Compatible challenges will prepare automatically as you reach them.