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
1Red 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:
local function award(coins, pickups)
return coins + pickups * 5
end
local function onPadTouched(playerName)
return award(10)
end
onPadTouched("Player1")
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?
Answer
Read the first red line: which script, which line, what happened. The first error line names the script, the line number and the problem. That is usually enough to find it.
Open this step in lesson mode · Link to this step · This confused me
2Who, 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.
Answer
ServerScriptService.Server.CoinService: Which script; 48: Which line; attempt to index nil: What it tried: reading a field from nothing; 'Coins': The field it tried to read. 'Index' means reading a field with a dot or brackets. Something on line 48 was nil, and the code tried to read .Coins from it.
Open this step in lesson mode · Link to this step · This confused me
3Five 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 |
local profiles = { Player1 = { coins = 5 } }
print(profiles.Player1.coins)
print(profiles.Player2.coins)
What error does this produce?
local Shop = {}
function Shop.buy(name)
return true
end
Shop.Buy("Player1")
Answer
main:5: attempt to call a nil value. Shop.Buy with a capital B does not exist, so it is nil, and calling nil fails on line 5. Names are case-sensitive.
Open this step in lesson mode · Link to this step · This confused me
4Read the message literally
Messages are short and exact, so read every word. This one surprises people:
local coins = nil
if coins > 10 then
print("rich")
end
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)
Answer
main:2: attempt to concatenate string with nil. local playerName with no value is nil, and .. cannot join text with nil. tostring(playerName) would print 'nil' instead of failing.
Open this step in lesson mode · Link to this step · This confused me
5The 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.
Answer
1. Line 7 calls onPadTouched("Player1") 2. Line 5 calls award(10), with no second argument 3. Line 2 multiplies pickups, which is nil, by 5 4. Luau raises the error and the trace is printed. The trace lists these newest first; reading it bottom-up gives the order they happened.
Open this step in lesson mode · Link to this step · This confused me
6Where 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?
Answer
Line 5: award(10) leaves out the second argument. Line 2 only noticed the nil. The nil came from line 5, which left out an argument. Walk down the trace until you reach the line where the bad value was created. A guard on line 2 can still be a sensible extra, but it is a patch, not the cause.
Open this step in lesson mode · Link to this step · This confused me
7Look 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.
local function award(coins, pickups)
print("award got", coins, pickups, type(pickups))
return coins + pickups * 5
end
print(award(10, 2))
print(award(10, "2"))
print(award(10))
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?
Answer
print("line 29", theValuesUsedOnLine30, type(theValueThatMightBeNil)). Show the actual values and their types. 'here' only proves the line ran.
Open this step in lesson mode · Link to this step · This confused me
8Search 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
- I can name the three parts of an error line: which script, which line and what happened
- I can read a stack trace from the bottom up
- I know to print values and their types to find where a nil came from
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?
Answer
The Players class page in the Engine API reference. The API reference is official and current, and each event lists its parameters. Old videos often show APIs that have since changed.
Open this step in lesson mode · Link to this step · This confused me
9The 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?
Answer
Saying what you want to achieve, what goes wrong and what you tried; Pasting your code as text in triple backticks; Searching the forum before posting. Text can be read, searched and copied. Asking for a whole system belongs in a hiring category, not support.
Open this step in lesson mode · Link to this step · This confused me
10Shrink 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:
-- Minimal reproduction: buying the Shield always fails, even with 50 coins.
local PRICES = { Speed = 25, Shield = 40 }
local coins = 50
local item = "shield"
print(PRICES[item])
print(coins >= PRICES[item])
The reproduction made the cause obvious. Fix it so the last line prints true.
local PRICES = { Speed = 25, Shield = 40 }
local coins = 50
local item = "shield"
print(coins >= PRICES[item])
Answer
Line 3: local item = "shield". Fixed: local item = "Shield". Keys are case-sensitive: "shield" is not "Shield", so the lookup returned nil. Printing PRICES[item] on its own line showed that at once.
Open this step in lesson mode · Link to this step · This confused me
11Ask 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
- Goal: what I am trying to do, in one sentence
- Expected and actual: what I expected, and what happened instead
- The exact error, copied as text, including the stack trace
- A minimal reproduction, as text in a code block
- What I tried, and what each attempt did
- My setup: Windows or macOS, and where I ran the code (the browser runner or Studio)
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?
Answer
'Buying Shield fails with 50 coins. Expected true, got: main:7: attempt to compare nil <= number. 6-line repro below. I checked the price table and it has Shield = 40.'. It has the goal, expected and actual, the exact error, a small reproduction and what was checked. A helper can answer it in a minute.
Open this step in lesson mode · Link to this step · This confused me
12AI 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?
Answer
'Here is my error and the 8 lines around it. Explain what the message means and give me one hint, not the fix.'. It asks for understanding and a hint, with just enough context. The cookie prompt is never acceptable: it hands over your account.
Open this step in lesson mode · Link to this step · This confused me
13Which 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?
Answer
A general chat assistant, with the error text and a minimal reproduction pasted in. A chat assistant sees only what you paste, which is all it needs to explain a message. Tools that can edit your project are useful too, but review what they change.
Open this step in lesson mode · Link to this step · This confused me
14Check 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?
Answer
Search the Player page in the Engine API reference, find no AddCoins, and ask the AI where that method comes from or how coins are really stored. The API reference is the source of truth. A method that is not listed there does not exist, however confident the suggestion sounded.
Open this step in lesson mode · Link to this step · This confused me
15Challenges
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 in the lesson view; 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
Hints
- The error says: attempt to get length of a nil value. Which name on that line is nil?
- Names are case-sensitive. After that, what does 0 / 0 give for an empty list?
Solution
local function average(list)
if #list == 0 then
return 0
end
local total = 0
for _, n in list do
total += n
end
return total / #list
end
-- average should return the mean of a list of numbers, or 0 for an empty list.
-- Run it: it fails. Read the error, find the cause, fix it.
local function average(list)
local total = 0
for _, n in list do
total += n
end
return total / #List
end
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.
Hints
- Cut the code down until removing anything else makes the bug disappear.
Open this step in lesson mode · Link to this step · This confused me
16Recap
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?
Open this step in lesson mode · Link to this step · This confused me