attempt to index a nil value
The script uses a variable that does not exist yet. With frameworks it is usually the old shared object event.
The error
SCRIPT ERROR: @my_script/client.lua:42: attempt to index a nil value (global 'ESX')Why it happens
- The script still uses the removed
esx:getSharedObjectevent, soESXstaysnil. - The framework starts after the script.
- Player data such as
PlayerData.jobis read before the player has loaded.
How to fix it
- Get the framework object through its export:
Lua
-- ESX Legacy
ESX = exports['es_extended']:getSharedObject()
-- QBCore
local QBCore = exports['qb-core']:GetCoreObject()
- Ensure the framework before your script in
server.cfg, or adddependency 'es_extended'to the manifest. - Wait for the player before reading job data:
Lua
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
PlayerData = QBCore.Functions.GetPlayerData()
end)
- The number after the file name is the line. Check what is
nilon that line and guard it withif value then ... end.