How to Prevent NPC Vehicles from Auto-Deleting When Players Leave an Area?

Hello everyone,

I’m running a FiveM server using the Qbox framework with the latest FiveM artifact and Element Club Aurum subscription. I’ve noticed that NPC vehicles (AI-spawned) automatically despawn when players leave a specific area.

I want to disable this auto-deletion so that NPC vehicles remain in the world even when no players are nearby.

Does anyone know of a solution or a way to configure this behavior? Any help would be appreciated!

Thanks in advance!

2 Likes

You need a “persistent vehicles” -type script, there are several to choose from on the forums.

1 Like

Thanks for the suggestion! I’ve already tried a few persistent vehicle scripts, but they only seem to work for player-owned vehicles and don’t affect NPC vehicles or default AI-spawned vehicles.

I need a solution that specifically prevents NPC vehicles from despawning when no players are nearby. Do you know of any script or method that can handle this?

Really difficult to not advertise here… :sweat_smile:

My script (AdvancedParking) can save (in theory, would need to be implemented separately) every single vehicle on your server. (Though I would argue that this could impact performance significantly)

There is a client side export that allows to save any vehicle. This could be implemented by using the entityCreated event and triggering a client event from there.

By default AdvancedParking saves any vehicle a player has entered/left (including NPC vehicles if it’s not disabled via config).

1 Like

Hey, I’m using Qbox, which has a vehicle persistence system that saves spawned vehicles. The issue I’m facing is with regular traffic vehicles (AI-spawned cars). When a player enters an NPC vehicle and then leaves it, the vehicle gets deleted after some distance. Does your script (AdvancedParking) have a solution to prevent these NPC vehicles from despawning?

AdvancedParking (AP) should not be used with other persistence systems as it is very easy for those to clash with each other.
If you just need it for saving NPC vehicles, I suggest looking elsewhere, sorry. The intention behind AP was to dynamically save all vehicles players interacted with and that is usually how it is used. Many also use it to only save player owned vehicles, though not vice versa as you suggest.

AP is also used to save vehicles across server restarts. So might not be exactly what you are looking for :sweat_smile:

(also as a qbox user you currently would have to use the experimental version, the live version is missing something critical (qbox’ vehicle identifier is not stored properly))