attempt to index a nil value
Also seen as: attempt to index a nil value (global 'ESX') attempt to index a nil value (global 'QBCore') attempt to index a nil value (local 'xPlayer') attempt to index a nil value (field 'Functions')
What causes it
Your code tried to read a field on something that is nil — a variable expected to hold a table or object doesn't exist yet. The message names the variable in parentheses, which is your fastest clue. The usual culprits are: a framework object (ESX/QBCore) that hasn't initialized before your script runs, a missing Config value, a load-order problem inside your own resource, a typo, or a player who disconnected mid-script.
How to fix it
Read the variable name in parentheses — that's what is nil. Then trace why it's nil at that point.
- Look at the file and line in the error (e.g.
@my_resource/server/main.lua:42) and read the code around it. - If the nil is
ESXorQBCore: your framework object isn't loaded yet. On ESX 1.9+, useESX = exports['es_extended']:getSharedObject()instead of the oldTriggerEvent('esx:getSharedObject')pattern. - If the nil is
Configor a key inside it: in fxmanifest.lua, make sureconfig.luais listed inshared_scriptsBEFORE any file that reads it. - If the nil is a player object (
xPlayer,Player): the player may not exist yet or disconnected. Guard it:if not xPlayer then return end. - If it's a dependency's export: make sure that resource is started before yours in server.cfg.
Related errors
Related guides
Still stuck? We can help.
Optimized, dual-framework scripts for QBCore and ESX from Viper Development — escrow protected, delivered instantly to your Cfx portal.