ESX / QBCore / Core object is nil
A script could not find your framework (ESX, QBCore, Qbox) — either it is not running, or it starts after this script does.
Do this first
In server.cfg, make sure your framework is listed ABOVE the script that failed.
What it means
The script tried to use the framework's shared object before it had one. The error itself usually arrives as attempt to index a nil value (global 'ESX'), but the cause is specific enough to deserve its own answer.
What causes it
Ordered by how often it is the answer.
- 1
The old getSharedObject pattern, still at file scope
ESX = nil TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)This is asynchronous. Any code below it runs before the callback does. ESX Legacy removed the event entirely, so on a modern server it never fires at all.
- 2
The framework is not started, or starts after your resource
ensure es_extendedbelowensure my-scriptin server.cfg. - 3
The wrong accessor for the installed version
ESX Legacy exports
getSharedObject; QBCore exportsGetCoreObject; Qbox prefers requiring its module. Using the other framework's call gets nil. - 4
Using it on the wrong side
The client and server objects are different. A server-only method called on the client is nil even when the object loaded.
How to tell which one is yours
print(GetResourceState('es_extended'), ESX ~= nil)If the state is started but ESX is nil, it is the accessor or the timing. If the state is anything else, it is server.cfg.
Where to look
The top of the failing file, and the ensure order in server.cfg.
How to fix it
ESX Legacy — direct, synchronous, no callback:
ESX = exports['es_extended']:getSharedObject()
QBCore:
local QBCore = exports['qb-core']:GetCoreObject()
Qbox:
local qbx = exports.qbx_core
If you must support an old ESX, at least wait for it before using it:
CreateThread(function()
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Wait(100)
end
end)Still stuck on your own code?
This page is what this error usually means. Paste your console into Server Fixer and it will rank everything in it and tell you what to do first, and if you would rather not touch it, ORBIE can repair the script and hand the resource back ready to drop in.
bug_reportOpen Server Fixer