CreateVehicleServerSetter (Serverside Spawned Vehicles) Despawning

Hey, I wanted to share some knowledge about a bug that causes vehicles to despawn, even when they’re spawned on the serverside. Normally, serverside spawning should prevent despawning, but it doesn’t seem to be working as expected. I’ve done a lot of testing and debugging with many players to gather as much information as possible.

FiveM Basic Information:

  • Client: Both Release and Beta version
  • FxServer Version: b7604
  • Bug Category: Affects both client and server side

Here’s what I found:
During debugging, I created a small script to check all vehicles using the GetAllVehicles function on the server side. This allowed me to check the last position, owner, and network ID of the despawned vehicle. First, I cached all vehicles and then checked if they still existed. I observed that despawning only occurs when a player owns the vehicle. I’ve never seen a despawned vehicle with the owner being “-1” (indicating the server).

Some information from our community suggests that despawning happens when entering any type of interior (MLO) while the vehicle is still within your proximity, thus making you the owner. It seems like some sort of client-side “clean up” occurs at this point. The game mistakenly believes it no longer needs the vehicle and deletes it on the client side. We suspect that once a client takes ownership of the vehicle, the clientside behavior mirrors what happens with client-spawned vehicles: it gets deleted when the game perceives it as unnecessary.

We’re still in the process of debugging this problem to find a solution as quickly as we can. From my perspective, it appears to be a clientside issue that could potentially be resolved by identifying the function responsible for cleaning up vehicles on clientside.

1 Like

Experienced something similar with players on our servers, but it only seems to affect random individuals. I never had it happen to me, but plenty of players reported similar experiences/issues with server-side spawned vehicles.

I have seen many problems that usually relate to some sort of sudden change of player position (aka “teleport”). As you already mentioned with the following:

Maybe there is a difference between “slowly going out of scope” and a sudden “teleport over 1000+ meters”. I would assume the latter can prevent some sort of handshake when trying to transfer ownership back to the server as the entity is simply immediately deleted?

When I’m doing calls/screenshare with customers to test out specific edge cases they might have with my scripts, I often see them using teleports or flying really fast using noclip. And I find many things just by looking at their screenshare or they tell me about certain things happening when doing so (unrelated to my scripts). Then I ask them if it also happens without teleporting/noclip and the answer is usually that their issue does not occur anymore.

There is a whole heap of issues I’ve seen like that but nothing I can officially confirm by myself but all of them usually relate around (de)spawning of entities (vehicles, objects, peds) especially with other players in proximity.

Server-side vehicles currently aren’t persistent and can despawn.