First steps, lesson 2
Comments and reading errors
Goal: Leave notes in code and find the line an error points at.
about 4 min3 practice exercises
A comment is a note for humans. Luau ignores everything after -- on a line.
-- Give the player their starting coins
print("You start with 0 coins") -- this part is ignored too
Comments explain why code exists. Good ones save you time when you come back to a script a month later.
When code breaks
Everyone writes code with mistakes. Roblox tells you where: an error in Output names the script, the line number and what went wrong.
ServerScriptService.CoinScript:3: attempt to call a nil value
Read it in three parts: the script (CoinScript), the line (3), the problem. "Attempt to call a nil value" usually means a misspelled function name, such as pritn instead of print. Luau is case sensitive, so Print is not print either.
Try it in Studio
Optional, and the best way to make it stick.
Misspell print in your script on purpose, press Play, and click the red error in Output. Studio jumps to the line.
Sources
Checked against Roblox's documentation on . The lesson is in our own words; these pages are the source of truth.