Module 7 · Tables and Luau types
Nested tables
Read a player profile one explicit path at a time without over-nesting.
What you will learn
- Access a value in a nested table
- Name an intermediate table to simplify a path
- nested table
- A table stored as a value inside another table.
- path
- The sequence of keys used to reach a nested value.
Loading saved progress…
Understand
Read the idea and follow a worked example.
Why this matters
A Coin Quest profile can group identity, currency, and settings while keeping each category understandable.
The mental model
Read a path from left to right: profile, then stats, then coins. Each step must produce a table before the next key can be read.
Use an intermediate local when a long path is repeated or when you need to inspect one layer.
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 “opening and closing braces”: it creates a table value around its entries.
= is read as “is assigned”: it evaluates the right side and stores that value in the name on the left.
. is read as “dot”: it accesses a named property or table field.
A tiny example
--!strictlocal profile = { name = "Ari", stats = { coins = 12, level = 2, },}local stats = profile.statsprint(profile.name, stats.coins)Line by line
- 3
profile is the outer dictionary.
- 4
name is a direct field.
- 5
stats maps to another table.
- 6
coins lives one level inside stats.
- 11
The intermediate local names the nested category.
- 12
The path to coins is now short and explicit.
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: profile is the outer dictionary.
Line 4: name is a direct field.
Line 5: stats maps to another table.
Line 6: coins lives one level inside stats.
Line 11: The intermediate local names the nested category.
Line 12: The path to coins is now short and explicit.
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 added field is reachable through a short, explainable path.
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 expression reaches level directly?
Try it
Mark each step after you have tried it.
Common mistake
Deeply nesting every tiny detail makes updates and missing data harder to trace. Group only values that genuinely share a category.
Checkpoint
Submit once you have considered every question. Retries are unlimited.
Recap
- Nested tables group related categories.
- Paths are read one key at a time.
- Intermediate locals keep deep access understandable.
Next: Next, you will ask Studio to analyze table and function types in strict mode.
Studio Companion
Not connected
Connect once. Compatible challenges will prepare automatically as you reach them.