Scripts

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:getSharedObject event, so ESX stays nil.
  • The framework starts after the script.
  • Player data such as PlayerData.job is read before the player has loaded.

How to fix it

  1. Get the framework object through its export:
Lua
-- ESX Legacy
ESX = exports['es_extended']:getSharedObject()

-- QBCore
local QBCore = exports['qb-core']:GetCoreObject()
  1. Ensure the framework before your script in server.cfg, or add dependency 'es_extended' to the manifest.
  2. Wait for the player before reading job data:
Lua
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
    PlayerData = QBCore.Functions.GetPlayerData()
end)
  1. The number after the file name is the line. Check what is nil on that line and guard it with if value then ... end.