Error fix

attempt to index a nil value (global 'QBCore'): causes and fix

Why FiveM scripts throw "attempt to index a nil value (global 'QBCore')" and the four fixes that solve it: start order, the core object export, dependencies and typos.

Updated 29 November 2026

This SCRIPT ERROR means the script tried to use the QBCore table before it existed. Lua found nothing in the global QBCore, so every QBCore.Functions call after that fails. The resource name in the error (the part after @) tells you which script to look at.

SCRIPT ERROR: @my_script/client/main.lua:12: attempt to index a nil value (global 'QBCore')

1. The script never fetches the core object

Current QBCore does not create a global QBCore for other resources. Each script must ask for it. Old scripts used an event that newer cores removed. Add this line at the top of every client and server file that uses QBCore:

local QBCore = exports['qb-core']:GetCoreObject()

If the script still contains TriggerEvent('QBCore:GetObject', function(obj) QBCore = obj end), replace it with the export above.

2. The script starts before qb-core

If my_script starts first, the export call runs before qb-core is ready. In server.cfg, make sure qb-core is ensured before your scripts, and declare the dependency in the script's fxmanifest.lua so FiveM starts it in the right order:

dependencies {
    'qb-core'
}

3. The script was written for ESX or Qbox

A script made for ESX will use ESX objects, and a Qbox-first script may use exports.qbx_core instead. Check the framework the script was written for. If it is ESX, see our ESX to QBCore conversion guide.

4. A typo or renamed core resource

The export name must match the folder name of your core resource exactly. If your core folder is not called qb-core, change the export call to match it.

Quick checklist

  1. Find the resource name after @ in the error.
  2. Add local QBCore = exports['qb-core']:GetCoreObject() to each file that uses QBCore.
  3. Add qb-core to dependencies in fxmanifest.lua and ensure it first in server.cfg.
  4. Restart the resource (ensure my_script) and watch the console.

Paste the error into FiveDev in-game and it reads the resource, finds the cause and proposes the fix for you to review.