Skip to content
Blog

FiveM SCRIPT ERROR: how to read it and fix the resource

SCRIPT ERROR: attempt to index a nil value and other FiveM console errors explained: the file and line to open, the usual causes and the fixes.

By Termi

5 min read
  • Errors
  • Lua
  • Debugging
  • Server health
On this page

Every FiveM server console prints red SCRIPT ERROR lines, and a busy server prints hundreds a day. Most come from a handful of mistakes that repeat across resources. This guide shows how to read one, what the common messages mean and how to find the few errors worth fixing first.

How to read a SCRIPT ERROR

server console
[ script:qb-garages] SCRIPT ERROR: @qb-garages/server/main.lua:57: attempt to index a nil value (local 'Player')
[ script:qb-garages] > handler (@qb-garages/server/main.lua:57)
  • @qb-garages is the resource, server/main.lua the file inside it and 57 the line.
  • The text after the line number is the Lua error. In parentheses, Lua names the variable: local 'Player' means a local variable called Player held nil.
  • Lines that start with > are the stack, newest call first. When the top line points into a framework or library such as es_extended or oxmysql, read down to the first line in a resource you run yourself. That is usually where the bad value came from.

Common errors and their fixes

attempt to index a nil value

The script reads a field from something that doesn’t exist. On ESX and QBCore it is almost always the player object, fetched for a player who has already left or hasn’t finished loading:

server/main.lua
local Player = QBCore.Functions.GetPlayer(source)
if not Player then return end
local cash = Player.PlayerData.money.cash

The check on the second line is the fix, and the same applies to ESX.GetPlayerFromId(source). When the message names a field, as in (field 'PlayerData'), the table above it exists but has no such key, which often means a script written for another version of the framework.

attempt to call a nil value

The script calls a function that doesn’t exist, and the parentheses name it: (field 'GetPlayerData') or (method 'addMoney'). The usual causes are a function the framework renamed in an update, a resource that defines it but starts later, or a global such as ESX that was never set. Newer ESX hands out its object through exports['es_extended']:getSharedObject() or @es_extended/imports.lua, and a script still waiting on the old esx:getSharedObject event can end up without it.

No such export in resource

No such export SendAlert in resource ps-mdt means a script called exports['ps-mdt']:SendAlert() and ps-mdt has no export by that name, at least not yet. Either the resource hasn’t started, it runs under a different folder name, or the export was renamed. Put the resource that provides the export earlier in server.cfg, and check the name against its fxmanifest.lua or its documentation.

attempt to perform arithmetic on a nil value

Something like count + 1 where count is nil, usually a value read from the database or a config key that doesn’t exist. Give it a default where it is read: local count = row.count or 0.

attempt to compare number with nil

The same cause in a comparison: if amount > Config.Limit with Limit missing from your config. Check that every key the script reads exists in your copy of config.lua, especially after an update that added new ones.

Errors from JavaScript resources

JavaScript resources print SCRIPT ERROR: followed by a JavaScript error and an at stack. TypeError: Cannot read properties of undefined (reading 'citizenid') is the JavaScript version of indexing nil, and it takes the same check.

Error running system event handling function

This line means a handler for a built-in event such as playerDropped or onResourceStart threw. The lines under it name the file and line, the same as a normal SCRIPT ERROR.

Which errors to fix first

A console with five hundred errors usually holds twenty different ones. Fix them by impact: first the error that hit the most players, then anything new since the last restart, which is usually the update you just shipped. With the console saved to a file, this counts errors by location:

terminal
grep -o 'SCRIPT ERROR: @[^:]*:[0-9]*' console.log | sort | uniq -c | sort -rn | head -20

It only counts lines, so one player stuck in a loop can push a harmless error to the top, and a loud error from yesterday looks the same as one that started an hour ago.

Let FiveDock group them

The FiveDock agent reads the server console as it prints. It joins each SCRIPT ERROR with its stack, masks player names, IP addresses and identifiers, and groups errors by resource, file, line and message, with the numbers in the message ignored so the same bug counts once.

On Metro, Error Hunter lists those groups with a count, the number of players hit and when each was first and last seen, with anything new since the restart on top. Deploy Guard takes a backup before a restart, gives a verdict ten minutes after it and names the resource behind any new trouble.

The agent is one resource with no open ports. Start it before your framework so it sees errors from the first second of a boot.

Common questions

What does attempt to index a nil value mean in FiveM?

The script tried to read a field from a variable that is nil, and the name in parentheses tells you which variable. On ESX and QBCore it is usually a player object fetched for a player who disconnected or hasn’t loaded, and the fix is to check the object exists before using it.

How do I find which resource causes a SCRIPT ERROR?

The resource is the name after @ at the start of the location, as in @qb-garages/server/main.lua:57. If that is a framework or library, read the stack lines that start with > until you reach the first one in a resource you run yourself.

Why do SCRIPT ERRORs appear after updating a resource?

Updates rename functions and exports, add config keys and expect newer versions of the framework. Compare the new config.lua with yours, check the changelog for renamed exports, and restart resources that depend on the one you updated.

Can I hide SCRIPT ERRORs from the console?

You can wrap calls in pcall, but that hides the bug and leaves in place whatever it broke. Fix the nil value where it comes from, and group the errors to see which ones matter.

All articles