Engineering
The FiveM Lua errors you will see most, and their fixes
Fix the most common FiveM Lua errors: attempt to index a nil value, attempt to call a nil value, arithmetic or concatenate on nil, bad argument to ipairs, compare number with nil, 'end' expected, No such export, and more — each with the usual cause.
Overview
Most FiveM errors are one of about a dozen messages, and each has a short list of usual causes. Learning to recognise them turns a scary red line into a two-minute fix. Every entry below shows the message, what it really means and where to look.
attempt to index a nil value
SCRIPT ERROR: @garage/client.lua:41: attempt to index a nil value (local 'vehicle')You wrote vehicle.plate (or vehicle[1]) while vehicle was nil. Typical causes: a callback or export returned nothing, a database query found no row, a config key is misspelled, or a framework object was read before the player finished loading.
local vehicle = lib.callback.await('garage:getVehicle', false, plate)
if not vehicle then
return print('no vehicle for plate ' .. tostring(plate))
end
print(vehicle.plate)attempt to call a nil value
You called something as a function that is not one. Common causes:
- A typo in the function name (
TriggerServerEvnt). - A client-only native used on the server, or the reverse.
- A framework function that does not exist in your version.
- A library not loaded: missing
@ox_lib/init.luain the manifest. - A local function defined below the line that calls it.
arithmetic, concatenate and compare on nil
| Message | Means | Fix |
|---|---|---|
attempt to perform arithmetic on a nil value | x + 1 where x is nil | Default it: (x or 0) + 1 |
attempt to concatenate a nil value | 'Hi ' .. name where name is nil | 'Hi ' .. tostring(name) or check first |
attempt to compare number with nil | if money > 100 where money is nil | Make sure the value loaded |
attempt to compare two table values | Comparing tables with < | Compare a field, not the tables |
bad argument #1 to 'ipairs' (table expected, got nil)
You looped over something that is nil: for _, v in ipairs(Config.Shops) where Config.Shops does not exist (a typo, or the config file loads after the script). Check the name and the order of files in the manifest — configs belong in shared_script before the scripts that read them.
Syntax errors
| Message | Usual cause |
|---|---|
'end' expected (to close 'function' at line N) | A missing end; count your if/for/function blocks |
unexpected symbol near | A missing comma in a table, or a stray character |
'=' expected near | A keyword typo, e.g. locla x = 1 |
unfinished string near | A missing closing quote |
FiveM-specific messages
| Message | Usual cause |
|---|---|
No such export … in resource … | Resource not started, wrong name or wrong side — see exports |
stack overflow | A function that calls itself forever, or an event handler that triggers its own event |
Failed to load script | A syntax error in that file |
| Game freezes on resource start | A while true do loop without Wait |
Where these messages appear and how to read them is covered in F8 and server console errors.
Frequently asked questions
What does 'attempt to index a nil value' mean?
You used . or [] on a variable that is nil. The error message names the variable; find out why it has no value at that line.
What does 'attempt to call a nil value' mean?
The function you called does not exist — a typo, a missing library, or a native from the wrong side.
Why do I get 'end' expected?
A block (if, for, function) is missing its end. The line in the message is where Lua noticed, not always where the mistake is.
How do I stop nil errors?
Check values that may be missing before using them, and give defaults with x or default.
Need this built, not just explained?
Ten years of FiveM work, from Lua to NUI
Custom resources, React NUI, ESX / QBCore / Qbox integration, OneSync performance audits and security reviews — plus the websites and SEO around your server brand.
Related guides
- Getting startedWhere FiveM errors appear and how to read themClient script errors appear in the F8 console in game; server script errors appear in the server console (or txAdmin’s Live Console). A SCRIPT ERROR: @resource/client.lua:23: attempt to index a nil value (local 'data') line tells you the resource, the file, the line number and what went wrong. Read the first error, not the last — later errors are often consequences of the first.
- Getting startedThe Lua you need for FiveM, from zeroAlways declare variables with local. Lua has nil, booleans, numbers, strings, tables and functions; only nil and false are falsy (0 and empty strings are true). Use if/elseif/else, numeric for i = 1, 10, for k, v in pairs(t) and while. Concatenate strings with .. and format with string.format. CfxLua adds vector3, backtick hashes, CreateThread and Wait.
- EngineeringExports: calling functions in another FiveM resourceDefine an export with exports('name', function(...) end) in Lua (or list the function under export/server_export in the manifest), then call it from another resource with exports.resource:name(...) or exports['resource-name']:name(...). Exports work on the same side only — client exports from client scripts, server exports from server scripts — and return values directly, unlike events.
- Getting startedSetting up VS Code for FiveM scriptingInstall the Lua extension (Lua Language Server by sumneko/LuaLS). Clone Overextended’s fivem-lls-addon — the replacement for the discontinued CfxLua IntelliSense extension — into a folder for Lua addons, point workspace.userThirdParty at that folder in a .luarc.json, and add ox_lib to workspace.library. For JavaScript/TypeScript, install @citizenfx/client and @citizenfx/server typings.