Entity state bag is not removed on client entity id

My understanding is that Entity(vehicle).state should be removed once entity no longer exists, but I am encountering strange issues with this.

Currently, I have a resource that spawns vehicle server side using CREATE_AUTOMOBILE and once it is created, it sets Entity(vehicle).state.jobVehicle to players identifier (license in this case), and on the client side, I check if entering vehicle have Entity(vehicle).state.jobVehicle and if it does, it should match with users identifier.

Issue that occurs here is following:

  • User selects to get vehicle, server creates vehicle, and sets state bag to his identifier and client receives networkid from vehicle as follows:
local playerID = getIdentifier(source)

local vehicle = Citizen.InvokeNative(GetHashKey('CREATE_AUTOMOBILE'), `flatbed`, vector3(truckSpawn.x, truckSpawn.y, truckSpawn.z), truckSpawn.w)
while not DoesEntityExist(vehicle) do Wait(100) end
local netid = NetworkGetNetworkIdFromEntity(vehicle)

Entity(vehicle).state.jobVehicle = playerID
TriggerClientEvent("send",  source, netid)
  • Player number 1 enters vehicle, it lets say it prints entity id from network id 768974

  • Player number 2, prints out that entity id is eg 578978

  • Once vehicle that player number one spawned is removed, it is removed server side using DeleteEntity(vehicle) and it is removed as it should, 578978 id for player number two does not exist anymore if checked.

  • After some time, Player number 2, pulls out vehicle from his private garage (job vehicle was flatbed, he pulls different model lets say sultan) locally that pulled vehicle get 578978 entity id, same as it was before for the players number 1 job vehicle and he is unable to enter vehicle.

  • If checked Entity(privatevehicle).state.jobVehicle it contains info from that old player one job vehicle

After doing relog/quit and join, probably, those ids get cleared, private vehicle gets different entity id and he can without issues enter vehicle. This is same case for all other users that this entity id is not 578978, but for all users where that private vehicle have 578978 entity id, they cannot enter vehicle.

TLDR I am not that into how these work, but I suspect that once entity is removed, state for it is not cleared for players client side. This usually happens when there is a “large” number of players on the server.

If any more info needed, please feel free to ask, hope this was clear. Thanks!

1 Like

Are the steps you’re providing in any way actually sufficient for reproducing this issue? I’m missing a lot of code in that case since ‘garages’ etc. are not a built-in concept.

Entity state does get cleared on entity removal both on client and server, so your deduction as to ‘what’s going on’ seems incorrect, also ‘where that private vehicle have 578978 entity id’ is nonsense as state fields are based on network ID and not pool index/entity handle: so please provide actual reproduction steps and not just some half code snippet and then steps that don’t have any equivalent without being ‘you’.