QBCore - get player job data dynamically

,

Hello,

I’m currently building a QBCore based script which gets a players job on server join and allows them to then run some commands depending on their and grade. I have this bit working, however, the problem I now have is that I cannot find a way to dynamically pull that job into my script if someone changes jobs or gets fired. If they were to relog onto the server it would update, but I would like this to be dynamic and update without relogging.

When a player joins the server this event is triggered

RegisterNetEvent('Threat:ChecksJobPerms')
Player = QBCore.Functions.GetPlayerData()
local jobName = Player.job.name
local jobRank = Player.job.grade.level
AddEventHandler('Threat:ChecksJobPerms', function()
    if jobName == "police" and Config.PEnabled == true and Config.PRank == Config.PRank and jobRank >= Config.PRank then
        PoliceCheck = true
    else 
        PoliceCheck = false
    end
    if jobName == "ambulance" and Config.AEnabled == true and Config.ARank == Config.ARank and jobRank >= Config.ARank then
        EMSCheck = true
    else
        EMSCheck = false
    end
    if jobName == "fire" and Config.FEnabled == true and Config.FRank == Config.FRank and jobRank >= Config.FRank then
        FireCheck = true
    else   
        FireCheck = false
    end
end)

I have confirmed it is pulling the correct values and working correctly through debugging and testing.

However, when someone changes jobs in the server the “jobName and jobRank” do not update, they stay as their old job.

When someone tries to run a command this command takes place

RegisterNetEvent('Threat:AllowUpdate')
RegisterCommand(Config.TLCommand, function()
    TriggerEvent('Threat:ChecksJobPerms')
    Citizen.Wait(1000)
    if EMSCheck == true or FireCheck == true or PoliceCheck == true then
    QBCore.Functions.Notify({text = 'This Would Work', caption = 'Job Test'}, 'police', 5000)
    else
     TriggerEvent('Threat:NoPerms')
    end
        
end)

Once again, works fine until they change jobs - at which point it keeps the old job and doesnt update to the new one.

Maybe i’m missing the point here but if im running the “Threat:ChecksJobPerms” function again then it should update to the players new job?

I have scoured around the web and the QBcore framework docs but cannot seem to find a way to rectify this.

Do I need to pull this from the server side instead and use a callback?

Thanks

You can listen to these events and update your local variables accordingly if need be. (if whatever resource that is changing the job is actually doing it through that player object function and not manipulating it through some other method. QB devs like to do funky things) https://github.com/qbcore-framework/qb-core/blob/083229887bedc8c0137ed40e40096b4a94829b49/server/player.lua#L217-L218

Did you ever figure this out? I am having the same issue.