Module 3 · Expressions, operators, and text
Joining and formatting strings
Use concatenation and Luau string interpolation to produce readable messages.
What you will learn
- Join strings with concatenation
- Insert values with string interpolation
- Choose readable formatting
- concatenation
- Joining text values with the two-dot operator.
- interpolation
- Inserting expression values into text marked with backticks.
Loading saved progress…
Understand
Read the idea and follow a worked example.
Why this matters
Coin Quest needs messages that include changing player names, scores, and time without storing a separate sentence for every possible value.
The mental model
Concatenation joins pieces with ... Interpolation uses backticks and braces to place an expression directly inside readable text.
Interpolation is often easier to scan when a message contains several changing values.
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 “concatenate”: it joins text values into a new string.
= 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 = 12local joined = "Player: " .. playerNamelocal summary = `{playerName} collected {coins} coins`print(joined)print(summary)Line by line
- 3
playerName is the changing text value.
- 4
coins is a number.
- 5
Two dots concatenate two strings.
- 6
Backticks enable interpolation; braces evaluate and insert values.
- 8
The simpler joined label is printed.
- 9
The complete interpolated sentence follows.
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: playerName is the changing text value.
Line 4: coins is a number.
Line 5: Two dots concatenate two strings.
Line 6: Backticks enable interpolation; braces evaluate and insert values.
Line 8: The simpler joined label is printed.
Line 9: The complete interpolated sentence follows.
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: Output contains a natural sentence with every current value inserted once.
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 sentence includes both current values?
Try it
Mark each step after you have tried it.
Common mistake
local summary = "{playerName} has {coins}"Ordinary quotes do not enable interpolation, so the braces remain literal text. Use backticks for an interpolated string.
Checkpoint
Submit once you have considered every question. Retries are unlimited.
Recap
- Concatenation joins text pieces.
- Interpolation inserts expression values into readable text.
- Formatting should preserve the meaning and type of source values.
Next: Next, you will combine calculation and formatting in a score summary.
Studio Companion
Not connected
Connect once. Compatible challenges will prepare automatically as you reach them.