ScriptsAboutBlogToolsKnowledge BaseReviewsFAQBasketDocsSupport
Frameworkcrash

attempt to index a nil value (field 'job')

Also seen as: attempt to index a nil value (field 'job') PlayerData.job nil job name nil ESX QBCore ESX.GetPlayerData job nil

What causes it

You read PlayerData.job (or .job.name) before the player's data finished loading. On first join the framework populates job asynchronously, so early code sees job as nil. Restarting the script in-game 'fixes' it only because you're already loaded by then — a classic timing bug.

How to fix it

Wait for the player to be fully loaded before reading job, and guard the access.

  1. Don't read PlayerData.job at the top level or immediately on resource start.
  2. QBCore: wait for the QBCore:Client:OnPlayerLoaded event, then read job; keep it updated via QBCore:Client:OnJobUpdate/OnPlayerUpdated.
  3. ESX: after getSharedObject, loop while ESX.GetPlayerData().job == nil do Wait(10) end, or handle esx:playerLoaded and esx:setJob.
  4. Guard access: if PlayerData.job and PlayerData.job.name then ... end.
  5. On resource restart, re-fetch: in onResourceStart for your own resource, call GetPlayerData() again.

Related errors

Related guides

Still stuck? We can help.

Viper Multi-Job lets players hold several jobs and switch between them with grade, salary and duty handled — QBCore, QBox and ESX, validated server-side.