Fundamentals: your first resource · Lesson 5/6 · 8 min
Read errors like a pro
Lua errors follow a pattern. Learn to read the stack trace and pinpoint the cause in seconds.
Programming is, to a large extent, reading errors. The FiveM console (F8 on the client, the server console / txAdmin on the server) tells you exactly which file and which line failed.
The most common error: indexing a nil
SCRIPT ERROR: @taxi_job/server.lua:14: attempt to index a nil value (local 'xPlayer')A typical error
It reads like this: in server.lua, line 14, you tried to access something (.dinero, .addMoney...) on a variable xPlayer that was nil. Translation: xPlayer doesn't exist. Common cause: the player isn't loaded yet, or the ID is wrong.
- attempt to index a nil value → you used something.field but «something» is nil.
- attempt to call a nil value → you called a function that doesn't exist (typo? misspelled export?).
- attempt to perform arithmetic on a nil value → you added/operated with a nil.
- attempt to concatenate a nil value → you joined text with a nil (..).
Tip: before using a variable that might be nil, check if xPlayer then ... end. Defensive programming prevents 80% of crashes.
In the Guides section you'll find detailed solutions to the most frequent ESX errors. Use it as a dictionary when you get stuck.
Challenge: code it yourself
You're given this error: attempt to call a nil value (field 'addMoneyy'). What's the most likely cause and how would you fix it?
Write it yourself in your editor (VS Code) and test it on your server. You learn here by doing it, not by copying.
See hint
Look closely at the method name... is it spelled correctly?
Escribe aquí tu solución:
