[FREE] [QBCORE] Vehicle Respawn Script / Prevent Vehicle Despawning

Hi everyone! :wave:

I was fed up with paid resources for basic functionality, so I created a vehicle respawn script for QBCore and decided to release it for FREE. :red_car::sparkles:

:scroll: What Does It Do?

This script helps keep vehicles in the world even if they despawn! It checks for vehicles that have despawned and respawns them with the same properties and at the same location as long as there’s a player nearby (minimum distance configurable). Perfect for ensuring vehicles don’t just vanish without reason during RP!

:wrench: Features:

  • Automatic respawn of despawned vehicles with the exact same location and properties.
  • Configurable check timer (default: every 2 minutes).
  • Ensures respawn only happens if no players are within 100 meters (configurable).
  • Lightweight and optimized for performance.
  • Built for QBCore servers, but can be easily adjusted for others.

:open_file_folder: Installation:

Make sure you have QBCore and baseevents installed

  1. Place the script in your resources folder.
  2. Add ensure vehicle-respawn to your server.cfg.
  3. Customize the configuration values if needed, and you’re good to go! :blue_car:

:hammer_and_wrench: How It Works:

  • Every [configurable interval], the script checks if any vehicles have despawned.
  • If a despawned vehicle is detected and there’s a player within the set radius (default: 100 meters), it respawns the vehicle at its last known location with all its properties intact.

:inbox_tray: Download:

[GitHub Repo]


:memo: Notes:

  • This script is not a despawn prevention tool but rather a respawn solution for despawned vehicles.
  • Tested on QBCore with excellent performance — should work on most setups with minor adjustments.

:speech_balloon: Feedback & Support:

I’d love to hear your feedback or suggestions! If you run into issues, drop a comment below or create an issue on the GitHub repo. Contributions are always welcome! :raised_hands:

Code is accessible Yes
Subscription-based No
Lines (approximately) 100
Requirements QBCore, baseevents
Support Yes
3 Likes

You can improve your logic with listening EntityRemoved event.

This unfortunately causes issues with vehicle garages from frameworks. If you put a car in your garage and leave, it will spawn back.

I didn’t test but I think this could also be used to duplicate cars? If you put a car away, get it back out and leave will the original car respawn?

It’s server event so it should be good, but you are right about garage scripts.

It can make cars impounded I guess.
The same goes for your current approach maybe?

As stated in the script, you need to add my event before every DeleteVehicle native

Sorry, correction, as its an older version of readme on this post, i’ll add the github readme here:

:warning: IMPORTANT NOTICE :warning:

To ensure proper functionality, you must call:
TriggerServerEvent('Ogi-NoDespawn:Server:RemoveVehicleNoDespawn', vehPlate)
before using any DeleteVehicle native in your client scripts. This also applies for any serverside scripts that uses the mentioned native.
This step is crucial to prevent issues with vehicle still respawning after deletion. Make sure to integrate it into every script where vehicles are being deleted.

Does this trigger when vehicle despawns due to onesync?

I guess so.

Just tested this, and yes, this event is triggered when vehicle despawns due to onesnyc. But now, what’s the point :smile:, how can i determine if that vehicle should have been kept or not.

Same with current logic you can store vehicles in variable and vehicle ID is exist in store, cancel event using CancelEvent() or respawn it again.

Just fyi:
As powerful as the entityremoved event is, it is not 100% reliable. There are still some edge cases where this might not be triggered. Similar to how server side vehicles are not 100% persistent due to network ownership issues. Additional checks should be kept in place to ensure these edge cases get caught.

1 Like

Thanks for the recommendation again. With the current logic i am not too comfortable using the event. What would happen if i cancelled it, that entity is still queued for deletion, so would it just try to delete it over and over again. Too many question and edge cases , still thanks!

1 Like