# ↘️ Autosave and Ownership

## 💾 Autosave

* **What it does:**\
  When `Config.Autosave` is set to `true`, the script will automatically save each vehicle’s mileage and wear data at regular intervals.
* **How often?**\
  Controlled by `Config.AutosaveInterval` (in seconds).\
  \&#xNAN;*Example: `10` means every 10 seconds.*
* **Loop prevent**\
  Minimum difference required between current mileage and last saved mileage to update the database\
  Controlled by `Config.MinDiffToSave`

## 🚗 Ownership

* **Config.BoughtVehiclesOnly:**
  * `true` = Only vehicles that are owned by players (from your vehicle database) will have mileage and wear tracked.
  * `false` = All vehicles, even those not owned, will be tracked (not recommended for most servers).
* **Config.VehDB:**
  * The name of your vehicle ownership table in the database (e.g., `player_vehicles` for QBCore).
  * Make sure this matches your framework’s vehicle table!

***

## **⁉️ Why use it?**

Prevents data loss if the server crashes or restarts unexpectedly.\
Players’ vehicle stats are always up-to-date!\
Prevents sql update loop to imrpove script & overall server performance

## 👀 Example configuration:

> 📝 **Pro Tip:**\
> For best performance and accurate tracking, keep autosave enabled and make sure your ownership table is set correctly!

```lua
Config.Autosave         = true          -- Enable autosave for mileage
Config.AutosaveInterval = 10            -- Autosave interval (seconds)
Config.MinDiffToSave    = 100.0         -- Minimum difference required between current mileage and last saved mileage to update the database
Config.BoughtVehiclesOnly = true        -- Only track owned vehicles
Config.VehDB            = 'player_vehicles' -- Vehicle ownership table
```
