> ## Documentation Index
> Fetch the complete documentation index at: https://docs.jaksam-scripts.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Fix hotwiring bought car

> Refresh a player's owned vehicles after a purchase so they don't have to hotwire it, for common vehicle shop scripts.

## Generic script

If you have to hotwire a vehicle right after purchasing it, add [this simple line of code](/vehicles-keys/client/refresh-self-owned-vehicles) to your script, after the vehicle has been added to the `owned_vehicles` / `player_vehicles` table (depending on the framework).

You may want to add a `Citizen.Wait(2000)` before that line, in case the vehicle wasn't yet in the table at the moment you triggered the event.

## esx\_vehicleshop

### First step

Go to `esx_vehicleshop/server/main.lua` and search for the following code:

<Frame>
  <img src="https://mintcdn.com/jaksam/cS_rA3IcGZ7NTj0G/images/esx_vehicleshop_setVehicleOwnedPlayerId_before.png?fit=max&auto=format&n=cS_rA3IcGZ7NTj0G&q=85&s=e4716ace29ef6a35dd97ce898aa02b53" alt="esx_vehicleshop setVehicleOwnedPlayerId before" width="1181" height="501" data-path="images/esx_vehicleshop_setVehicleOwnedPlayerId_before.png" />
</Frame>

And add this line:

```lua theme={null}
exports["vehicles_keys"]:refreshPlayerOwnedVehicles(playerId)
```

<Frame>
  <img src="https://mintcdn.com/jaksam/cS_rA3IcGZ7NTj0G/images/esx_vehicleshop_setVehicleOwnedPlayerId_after.png?fit=max&auto=format&n=cS_rA3IcGZ7NTj0G&q=85&s=40def4382895d1637d5fa1b938292e94" alt="esx_vehicleshop setVehicleOwnedPlayerId after" width="1164" height="524" data-path="images/esx_vehicleshop_setVehicleOwnedPlayerId_after.png" />
</Frame>

### Second step

Go to `esx_vehicleshop/server/main.lua` (the same file as before) and search for the following code:

<Frame>
  <img src="https://mintcdn.com/jaksam/cS_rA3IcGZ7NTj0G/images/esx_vehicleshop_buyVehicle_before.png?fit=max&auto=format&n=cS_rA3IcGZ7NTj0G&q=85&s=2fd37ee0d4f7f7d1c267b7dcf42ac2d3" alt="esx_vehicleshop buyVehicle before" width="985" height="512" data-path="images/esx_vehicleshop_buyVehicle_before.png" />
</Frame>

And add this line:

```lua theme={null}
exports["vehicles_keys"]:refreshPlayerOwnedVehicles(source)
```

<Frame>
  <img src="https://mintcdn.com/jaksam/cS_rA3IcGZ7NTj0G/images/esx_vehicleshop_buyVehicle_after.png?fit=max&auto=format&n=cS_rA3IcGZ7NTj0G&q=85&s=f3921278b259af0139f245d2bd054171" alt="esx_vehicleshop buyVehicle after" width="1094" height="581" data-path="images/esx_vehicleshop_buyVehicle_after.png" />
</Frame>

## esx\_advancedvehicleshop

Go to `esx_advancedvehicleshop/server/main.lua` and search for the following code:

<Frame>
  <img src="https://mintcdn.com/jaksam/cS_rA3IcGZ7NTj0G/images/esx_advancedvehicleshop_before.png?fit=max&auto=format&n=cS_rA3IcGZ7NTj0G&q=85&s=ea3f0101c1b2a6f096c73c2049924c9d" alt="esx_advancedvehicleshop before" width="1187" height="307" data-path="images/esx_advancedvehicleshop_before.png" />
</Frame>

And add this line:

```lua theme={null}
exports["vehicles_keys"]:refreshPlayerOwnedVehicles(source)
```

<Frame>
  <img src="https://mintcdn.com/jaksam/cS_rA3IcGZ7NTj0G/images/esx_advancedvehicleshop_after.png?fit=max&auto=format&n=cS_rA3IcGZ7NTj0G&q=85&s=d9dde06b64ab5df06d6c49c4a9c7b527" alt="esx_advancedvehicleshop after" width="1107" height="374" data-path="images/esx_advancedvehicleshop_after.png" />
</Frame>

## qb-vehicleshop

### First step

Go to `qb-vehicleshop/server.lua` and add the following code after **all** `exports.oxmysql:insert` calls.

<Note>
  In the example it's shown only once, but you have to add it multiple times.
</Note>

<Frame>
  <img src="https://mintcdn.com/jaksam/cS_rA3IcGZ7NTj0G/images/qb-vehicleshop_before.png?fit=max&auto=format&n=cS_rA3IcGZ7NTj0G&q=85&s=fa9adba006d8f86d14118fc878a796e4" alt="qb-vehicleshop before" width="1186" height="574" data-path="images/qb-vehicleshop_before.png" />
</Frame>

Add the following code:

```lua theme={null}
SetTimeout(1000, function()
    exports["vehicles_keys"]:refreshPlayerOwnedVehicles( pData.PlayerData.source )
end)
```

In certain parts, you'll have to replace `pData` with something else. Here it shows where to add the code and what `pData` depends on.

<Frame>
  <img src="https://mintcdn.com/jaksam/cS_rA3IcGZ7NTj0G/images/qb-vehicleshop_after.png?fit=max&auto=format&n=cS_rA3IcGZ7NTj0G&q=85&s=e764fda96d34d91445073783d69b59a9" alt="qb-vehicleshop after" width="1091" height="580" data-path="images/qb-vehicleshop_after.png" />
</Frame>

<Note>
  The green circles shown in the screenshot must match — so if the first one is, for example, `targetPlayer`, the second one must be `targetPlayer` as well.
</Note>

### Second step

Go to `qb-vehicleshop/server.lua` (the same file as before) and replace all these events (they're at the bottom of the file):

```lua theme={null}
TriggerClientEvent('vehiclekeys:client:SetOwner', buyerId, plate)
```

with the following code:

```lua theme={null}
exports["vehicles_keys"]:refreshPlayerOwnedVehicles(buyerId)
```

## okokVehicleShop

Go to `okokVehicleShop/sv_utils.lua` and search for the following code:

<Frame>
  <img src="https://mintcdn.com/jaksam/cS_rA3IcGZ7NTj0G/images/okokVehicleShop_before.png?fit=max&auto=format&n=cS_rA3IcGZ7NTj0G&q=85&s=71f1c3f9f24a7766656e4879cb36d8e8" alt="okokVehicleShop before" width="957" height="286" data-path="images/okokVehicleShop_before.png" />
</Frame>

And add this line:

```lua theme={null}
exports["vehicles_keys"]:refreshPlayerOwnedVehicles(_source)
```

<Frame>
  <img src="https://mintcdn.com/jaksam/cS_rA3IcGZ7NTj0G/images/okokVehicleShop_after.png?fit=max&auto=format&n=cS_rA3IcGZ7NTj0G&q=85&s=da2a21fcb702f8af26fba1fce8ef80d8" alt="okokVehicleShop after" width="952" height="317" data-path="images/okokVehicleShop_after.png" />
</Frame>

## s4-vehicleshop

Go to `s4-vehicleshop/server.lua` and search for the following code:

<Frame>
  <img src="https://mintcdn.com/jaksam/cS_rA3IcGZ7NTj0G/images/s4-vehicleshop_before.png?fit=max&auto=format&n=cS_rA3IcGZ7NTj0G&q=85&s=21eacff9b58cfa46655c3cbc3caafc74" alt="s4-vehicleshop before" width="1162" height="234" data-path="images/s4-vehicleshop_before.png" />
</Frame>

And add the following code:

```lua theme={null}
SetTimeout(1000, function()
    exports["vehicles_keys"]:refreshPlayerOwnedVehicles(src)
end)
```

<Frame>
  <img src="https://mintcdn.com/jaksam/cS_rA3IcGZ7NTj0G/images/s4-vehicleshop_after.png?fit=max&auto=format&n=cS_rA3IcGZ7NTj0G&q=85&s=e7a2356476bf1bb3eb29e9f464d67747" alt="s4-vehicleshop after" width="1177" height="309" data-path="images/s4-vehicleshop_after.png" />
</Frame>

<Note>
  This code works for both *oxmysql* and *ghmattimysql* versions.
</Note>

## t1ger\_dealerships

### First step

Go to `t1ger_dealerships/server/main.lua` and add the following line below **all** occurrences (more than one) of the code shown in the example:

```lua theme={null}
exports['t1ger_keys']:UpdateKeysToDatabase(props.plate, true)
```

<Frame>
  <img src="https://mintcdn.com/jaksam/cS_rA3IcGZ7NTj0G/images/t1ger_dealerships_before.png?fit=max&auto=format&n=cS_rA3IcGZ7NTj0G&q=85&s=8c9de0ebdd6178ff0903d0882a2f5758" alt="t1ger_dealerships before" width="964" height="155" data-path="images/t1ger_dealerships_before.png" />
</Frame>

Add the following line:

```lua theme={null}
exports["vehicles_keys"]:refreshPlayerOwnedVehicles(xPlayer.source)
```

<Frame>
  <img src="https://mintcdn.com/jaksam/cS_rA3IcGZ7NTj0G/images/t1ger_dealerships_after.png?fit=max&auto=format&n=cS_rA3IcGZ7NTj0G&q=85&s=4bc2250d15aca2b9ceaef6c5e6445389" alt="t1ger_dealerships after" width="982" height="414" data-path="images/t1ger_dealerships_after.png" />
</Frame>

### Second step

Go to `t1ger_dealerships/server/main.lua` (the same file as before) and search for the following code:

<Frame>
  <img src="https://mintcdn.com/jaksam/cS_rA3IcGZ7NTj0G/images/t1ger_dealerships2_before.png?fit=max&auto=format&n=cS_rA3IcGZ7NTj0G&q=85&s=ee0abf4e666352fa8d533852e8962253" alt="t1ger_dealerships2 before" width="1183" height="527" data-path="images/t1ger_dealerships2_before.png" />
</Frame>

Add the following line:

```lua theme={null}
exports["vehicles_keys"]:refreshPlayerOwnedVehicles(xPlayer.source)
```

<Frame>
  <img src="https://mintcdn.com/jaksam/cS_rA3IcGZ7NTj0G/images/t1ger_dealerships2_after.png?fit=max&auto=format&n=cS_rA3IcGZ7NTj0G&q=85&s=dcde43e20e39e19e8627359443d10c31" alt="t1ger_dealerships2 after" width="1156" height="573" data-path="images/t1ger_dealerships2_after.png" />
</Frame>


## Related topics

- [FAQ](/vehicles-keys/faq.md)
- [Toggle hotwiring](/vehicles-keys/client/toggle-hotwiring.md)
- [Vehicles Keys](/vehicles-keys/home.md)
- [Shop bought](/shops-creator/server/shop-bought.md)
- [Item bought](/jobs-creator/server/shop/item-bought.md)
