Hey everyone, running into something weird with statebags and hoping someone can shed some light on this.
I've got a custom vehicle ownership system where players can spawn personal vehicles, and I'm doing a job permission check using the player's statebag data. The issue is that right after a player changes jobs, the statebag still has the old job value even though the PlayerData shows the new job correctly.
Here's what I'm seeing:
RegisterNetEvent('qb-vehicles:server:spawnPersonalVehicle', function(vehicleProps)
local src = source
local Player = QBCore.Functions.GetPlayer(src)
local statebag = GetStateBagOfPlayer(src)
local playerJob = statebag.job or Player.PlayerData.job.name
if playerJob ~= 'mechanic' then -- This check sometimes fails due to stale statebag
TriggerClientEvent('QBCore:Notify', src, 'Not authorized for this vehicle type', 'error')
return
end
-- Vehicle spawn continues with potentially incorrect job data
end)This happens consistently when there's no delay between the job change and the vehicle spawn attempt. Anyone run into this timing issue with statebags before? Wondering if there's some sync delay I need to account for or if I should just be using PlayerData directly instead.
BlitzKrieg · 30/08/2026
Sign in to reply.