PiTyUs.Hire me

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.

Updated 12 min readBy PiTyUs · FiveM developer

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

Exampletext
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.

Fix: check before usinglua
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.lua in the manifest.
  • A local function defined below the line that calls it.

arithmetic, concatenate and compare on nil

MessageMeansFix
attempt to perform arithmetic on a nil valuex + 1 where x is nilDefault 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 nilif money > 100 where money is nilMake sure the value loaded
attempt to compare two table valuesComparing 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

MessageUsual cause
'end' expected (to close 'function' at line N)A missing end; count your if/for/function blocks
unexpected symbol nearA missing comma in a table, or a stray character
'=' expected nearA keyword typo, e.g. locla x = 1
unfinished string nearA missing closing quote

FiveM-specific messages

MessageUsual cause
No such export … in resource …Resource not started, wrong name or wrong side — see exports
stack overflowA function that calls itself forever, or an event handler that triggers its own event
Failed to load scriptA syntax error in that file
Game freezes on resource startA 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