Lesson 8 of 8
Reading errors, docs and getting help (including AI as a tutor)
Learn to read Luau errors and stack traces, search the docs and DevForum, build a minimal reproduction, and use AI assistants as a tutor.
By the end you can
- Read a Luau error and a stack trace to find the script, the line and the cause.
- Search the Roblox docs and the DevForum, and cut a problem down to a minimal reproduction.
- Ask a question that gets answered, and use an AI assistant as a tutor without letting it think for you.
Before this: Programming from zero, part 3: tables and the coin counter
Step 1 of 16
Red text is a gift
Sooner than you think, code you wrote will stop and print red text. It is tempting to read that as "you failed". Read it as "here is exactly what went wrong and where". Professional developers do not make fewer errors than beginners. They read them faster.
Run this cell. It has a bug on purpose, a small test of awarding coins:
The runner stops and shows one error line under the cell. By the end of this lesson every word of it will make sense. Real tools print more than the browser runner does, and you will meet them in the setup lessons. They add a trace under the line, and the trace gets its own step below.
Red text appears when you run your code. What is the best first move?
Press 1 to 4 to choose, Enter to check.
Step 2 of 16
Who, where, what
| In the picture | In Roblox |
|---|---|
| Which room | The script name or path |
| The zone number on the panel | The line number |
| What the detector sensed | The error message |
| The doors the smoke came through, nearest first | The stack trace |
Think of the panel by a building's front door. When a smoke detector trips, the panel does not just ring. It shows three things, and an error line shows the same three.

Every Luau error line has the same three parts.
- Who: the script's name. In a real game it is a full path, such as
ServerScriptService.ErrorDemo. In the browser runner your code is calledmain, so you sawmain:2:. - Where: the line number, between colons.
- What: the message. It names the operation that failed (
arithmetic (mul), so a*) and the kinds of value involved (nil and number).
Think of it as The panel by a building's front door, which names the room and the zone and lists the doors the smoke came through
Take: ServerScriptService.Server.CoinService:48: attempt to index nil with 'Coins'. Match each part.
Step 3 of 16
Five messages you will see a lot
Most beginner errors are one of a handful of messages. Each cell below triggers one on purpose; press Run and match it to the table.
| Message | What it means | Usual cause |
|---|---|---|
attempt to index nil with 'X' | You read .X from something that is nil | a misspelt name, or an object that does not exist yet |
attempt to perform arithmetic (add) on nil and number | You did maths with nil | a variable or argument never set |
attempt to call a nil value | You called something that is not a function | a misspelt function name |
attempt to compare number < nil | You compared a number with nil | a missing value in an if |
Expected 'end' (to close 'function' at line 1) | The code does not parse at all | a missing end |
What error does this produce?
local Shop = {}
function Shop.buy(name)
return true
end
Shop.Buy("Player1")
Press 1 to 4 to choose, Enter to check.
Step 4 of 16
Read the message literally
Messages are short and exact, so read every word. This one surprises people:
The code says coins > 10, but the message says number < nil. Luau turned a > b into b < a before running it, so the sides swapped. The message is still telling the truth: one side was a number and the other was nil. Find the nil.
What error does this produce?
local playerName
print("Welcome, " .. playerName)
Press 1 to 4 to choose, Enter to check.
Step 5 of 16
The stack trace: the doors the smoke came through
The first line says where the error happened. The lines that real tools print under it say how the program got there. Each function call waits on the one it called, like a stack of plates. The top line is the function that failed, and each line below it is the one that called the line above.
Both sidesRemember: An error message is the panel by a building's front door, which names the room and the zone and lists the doors the smoke came through.
Roblox Studio, which you install in the setup lessons, prints this trace for the cell you ran at the top of the lesson. Its first line has the same three parts as before:
ServerScriptService.ErrorDemo:2: attempt to perform arithmetic (mul) on nil and number
Stack Begin
Script 'ServerScriptService.ErrorDemo', Line 2 - function award
Script 'ServerScriptService.ErrorDemo', Line 5 - function onPadTouched
Script 'ServerScriptService.ErrorDemo', Line 7
Stack End
Read it from the bottom up to tell the story in order: line 7 called onPadTouched, which on line 5 called award, which failed on line 2. In Set up your machine, part 3: connect, play, and the optional extras you will make Studio print a trace like this for real.
Put the events in the order they happened.
- Line 7 calls onPadTouched("Player1")
- Line 5 calls award(10), with no second argument
- Luau raises the error and the trace is printed
- Line 2 multiplies pickups, which is nil, by 5
Step 6 of 16
Where the alarm picture breaks
A smoke detector sounds close to the fire. Errors do not. Luau stops where a bad value is used, which is often far from where it was made.
In the trace above, the error is on line 2, inside award. But line 2 is correct code. The mistake is on line 5, where award(10) forgot its second argument. Line 2 is just where the missing value was finally noticed.
Where does it break?“The panel by a building's front door, which names the room and the zone and lists the doors the smoke came through” is a good picture of an error message. Where does it stop being true?
It breaks here. A smoke detector sounds close to the fire, but an error sounds at the line that used a bad value, which can be far from the line that made it, and the trace lists only the calls still running.
The true model. The virtual machine raises an error at the instruction that fails, and the stack trace lists the active calls at that moment, innermost first. The cause can be any earlier code that produced the bad value.
Which line holds the cause of the nil in the ErrorDemo script, the place where the missing value should have been supplied?
Press 1 to 4 to choose, Enter to check.
Step 7 of 16
Look at the values
When the message is not enough, look at what the values actually are. Put a print just before the failing line, showing the values and their types. It is crude and it works, and professionals do it every day.
Look at the middle call. "2" is a string, and Luau quietly converted it to a number, so nothing failed. A print with type, which names the kind of value (number, string, nil), reveals bugs like that before they bite. Remove the prints when you are done. Studio's debugger, taught later, does the same job without editing code.
An error says nil on line 30. What is the most useful print to add on line 29?
Press 1 to 4 to choose, Enter to check.
Step 8 of 16
Search the docs first
Good place for a break. Your answers and progress are saved in this browser, so you can stop here and come back to this step. Tick what you can do now; if something is shaky, go back one step first.
Checkpoint
0 of 3 checked
The official documentation answers most "how does X work?" questions faster than any person can.
- Roblox Creator Hub docs, at
create.roblox.com/docs, cover Studio, guides and tutorials 1. - The Engine API reference has one page per class, such as
PlayersorPart, listing every property, method and event 2. If an API is not there, it does not exist. - luau.org documents the language itself: syntax, types and the standard library 3.
Search with the class and member name together, such as Players.PlayerAdded or TweenService:Create. Read the page's code sample before anything else; it is usually the fastest answer.

Select a numbered pin, or a row below, to read what it marks.
Search with the class and member name together.
You want to know what arguments Players.PlayerAdded passes to your function. Where do you look first?
Press 1 to 4 to choose, Enter to check.
Step 9 of 16
The DevForum
The Developer ForumDeveloper Forum (DevForum)Roblox's official forum for developers, where staff announce changes and people ask for help.Think of it as the notice board in the middle of the yard, read by everyone who builds. at devforum.roblox.com is where Roblox developers, and Roblox staff, discuss problems and announce changes 4. Search it before you post. Someone has very likely hit the same error and posted the answer.
If you do post, the Scripting Support category asks every topic to answer three questions: what you want to achieve, what the issue is (with screenshots or video if possible), and what you have already tried, including whether you checked the Creator Hub 5. Its rules also say to paste code as text between triple backticks, never as a screenshot, and not to ask people to write whole scripts or systems for you.

Select a numbered pin, or a row below, to read what it marks.
Search the exact error message, filtered to Scripting Support.
Which follow the Scripting Support rules?
Press 1 to 5 to choose, Enter to check.
Step 10 of 16
Shrink it: the minimal reproduction
The most powerful debugging skill has a name: the minimal reproductionMinimal reproductionThe smallest piece of code that still shows a bug.Think of it as the bug in a jar, with everything else removed.. Make a copy, then delete everything that is not needed to make the bug happen, until what is left is as small as it can be and still shows the problem 6.
Two things happen when you do this. Half the time you find the bug yourself while cutting, because the thing you just removed made it go away. The other half, you end up with ten lines that anyone can understand, instead of your whole game.
Here is a bug from a shop script, cut down from 80 lines to the few that matter. It runs in the browser, so anyone can try it:
The reproduction made the cause obvious. Fix it so the last line prints true.
Press 1 to 4 to choose, Enter to check.
Step 11 of 16
Ask a question that gets answered
When you do ask, in a "this confused me" issue, on the DevForum or to a friend, give the helper everything they need in one message:
Checkpoint
0 of 6 checked
Leave out passwords, cookies, API keys and your real name. Nobody needs them to help with code 7.
Which question is most likely to get a fast, correct answer?
Press 1 to 4 to choose, Enter to check.
Step 12 of 16
AI assistants as a tutor
AI assistants are now part of normal development. Roblox Studio has its own Assistant, which answers questions, explains selected code and can create and change objects and scripts in your place 8. Editors such as Cursor have one built in, and general chat assistants answer Luau questions too.
Used well, an AI is a patient tutor available at 3 a.m. Used badly, it writes code you do not understand, and you learn nothing. Rules for this course:
- Ask it to explain, not to fix. "What does attempt to index nil with 'coins' mean, and what should I check?" teaches you. "Fix my script" does not.
- Ask for a hint first. Try the hint before you ask for the answer.
- Check every API name it uses against the Engine API reference. AIs invent plausible methods that do not exist.
- Never paste secrets: cookies,
.ROBLOSECURITY, API keys or passwords. - You must be able to explain every line you keep. If you cannot, you are not finished.
Which prompt uses an AI as a tutor?
Press 1 to 4 to choose, Enter to check.
Step 13 of 16
Which assistant, for what
AI assistants you will meet
| Option | What it is | When pros pick it | Trade-offs |
|---|---|---|---|
| Studio Assistant | An assistant built into Studio that can see your place and act on it, so it can insert objects and edit scripts for you. | Quick experiments inside a place, with a person reviewing every change. | It changes things. Review its edits the way you would review a teammate's, and commit before asking for anything large. |
| An AI in your editor (Cursor and others) | An assistant that sees the files in your project folder, so it can explain code in context and point at the line it means. | Explaining unfamiliar code in a project you already understand a little. | It can change many files at once. Read its diff before you accept anything. |
| A general chat assistant | A chat window that sees only what you paste. | Explaining an error message or a minimal reproduction, as a tutor. | A poor judge of your whole game. Paste small snippets, never secrets. |
Sources: 8
You want an explanation of one confusing error message without giving anything access to your project. Which fits best?
Press 1 to 4 to choose, Enter to check.
Step 14 of 16
Check what the AI tells you
An assistant suggests this to award coins:
local function onTouched(player)
player:AddCoins(Config.COIN_VALUE)
end
It looks confident and tidy. Before using it, look up Player in the Engine API reference. There is no AddCoins method on Player. The AI invented it because the name sounds right. In Beacon Yard, coins live in the server's own data, which the coin and data lessons build, not on the Player object.
This is the habit that keeps AI useful: trust, then verify, against the docs, against a quick test, or against the error you get when you run it.
An AI's code calls player:AddCoins(5). What do you do?
Press 1 to 4 to choose, Enter to check.
Step 15 of 16
Challenges
Level 2, Builder
Challenge
This function fails. Read the error, find the cause and fix it so every test passes.
- Start from
- The code cell below the challenge, which runs a hidden test when you press Run.
- Check it here
- Run the code cell; the challenge completes when it passes. No Studio needed.
Done means
- average({10, 20, 30}) is 20
- average({}) is 0, not nan
- Self-check, not graded: you can say which line the error named and which line held the cause
Level 1, Apprentice
Challenge
Write one good question about a real bug, in the format helpers want to read.
- Start from
- A bug you hit in any lesson so far, or the award snippet from this lesson.
Done means
- You wrote a question with goal, expected, actual, the exact error text and what you tried.
- It includes a minimal reproduction of 15 lines or fewer, as text.
- It contains no personal details, passwords, cookies or keys.
Meet the criteria above, then record your own result. No test grades this check.
Step 16 of 16
Recap
Recap
- An error line says who (the script path), where (the line) and what (the rule broken). The stack trace lists the calls that led there, newest first; read it bottom-up for the story.
- Errors fire where a bad value is used, not where it was made. Print the values and their types, then shrink the problem to a minimal reproduction.
- Search the API reference, luau.org and the DevForum first. Ask with goal, expected, actual, exact error and repro. Use AI to explain and hint, verify every API it names, and never paste secrets.
An error message is the panel by a building's front door, which names the room and the zone and lists the doors the smoke came through, until a smoke detector sounds close to the fire, but an error sounds at the line that used a bad value, which can be far from the line that made it, and the trace lists only the calls still running.
Queued for review
- Take: ServerScriptService.Server.CoinService:48: attempt to index nil with 'Coins'. Match each part.
- Put the events in the order they happened.
- Which line holds the cause of the nil in the ErrorDemo script, the place where the missing value should have been supplied?
- An AI's code calls player:AddCoins(5). What do you do?