I am trying to get the players current job and having some issues. I have the following in my code;
local PlayerData = {}
ESX = nil
Citizen.CreateThread(function ()
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(0)
end
while ESX.GetPlayerData().job == nil do
Citizen.Wait(10)
end
PlayerData = ESX.GetPlayerData()
end)
RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function(xPlayer)
PlayerData = xPlayer
end)
RegisterNetEvent('esx:setJob')
AddEventHandler('esx:setJob', function(job)
PlayerData.job = job
LSCMenu:showNotification(PlayerData.job.name)
end)
however when i try to use
Citizen.CreateThread(function()
if PlayerData.job.name == 'police' then
--code here
end
end)
I get the error: attempt to index a nil value (field ‘job’)
am i missing anything or what am i doing wrong?