PlayerData is nil or empty on the client
A script asked for a player's information before the game had sent it. It usually works on join and breaks after restarting the script.
Do this first
Have the player rejoin. If it works then, the script needs a fix for restarts.
What it means
Client code read the player's data before the framework had sent it. The object exists but its fields are empty, or the whole thing is nil, so PlayerData.job.name fails.
This is a timing bug, not a data bug. The same code works after a few seconds, which is exactly what makes it confusing: it fails on server restart and on resource restart, and works when you test it by hand later.
What causes it
Ordered by how often it is the answer.
- 1
Reading it at file scope
The resource starts before the player is loaded. On a server restart every resource starts at once, with no player in the session at all.
- 2
Not listening for the loaded event
The framework announces when the data is ready. Code that never subscribes has to guess.
- 3
Not handling a resource restart while the player is already in
esx:playerLoadedfired long ago; restarting your resource means it never sees it. This is why a script works on join and breaks on/restart. - 4
Reading a sub-table that is populated later
PlayerData.jobcan arrive afterPlayerDataitself does.
How to tell which one is yours
Does it work when you rejoin but break when you restart the resource? Then it is cause 3, and it is the most commonly missed one.
Where to look
Wherever the file first touches PlayerData, and whether there is a loaded-event handler at all.
How to fix it
Subscribe, and also handle the already-loaded case:
local PlayerData = {}
RegisterNetEvent('esx:playerLoaded', function(xPlayer)
PlayerData = xPlayer
end)
RegisterNetEvent('esx:setJob', function(job)
PlayerData.job = job
end)
-- covers a resource restart with the player already in the session
AddEventHandler('onClientResourceStart', function(res)
if res ~= GetCurrentResourceName() then return end
if ESX and ESX.IsPlayerLoaded() then
PlayerData = ESX.GetPlayerData()
end
end)QBCore is the same shape with QBCore:Client:OnPlayerLoaded and QBCore.Functions.GetPlayerData().
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