FiveM garage: owned_vehicles and player_vehicles, missing cars fixed
Vehicles missing from the garage? How the ESX owned_vehicles and QBCore player_vehicles tables work, the stored and state columns, and the SQL to fix cars stuck out.
Typical symptoms:
You bought a car, and the garage says "No vehicles". Or the car was parked at the street, the server restarted, and it is gone.Almost every garage script reads the same thing: one table with a row per owned vehicle. When a car is missing, the row is wrong, not the script. This article explains the two standard tables, what the stored and state columns mean, and the SQL that fixes the usual cases.
The two tables
ESX uses owned_vehicles. QBCore and QBox use player_vehicles. The names are the same across servers, the exact columns depend on your version and your garage script, so look at yours first:
DESCRIBE owned_vehicles;
DESCRIBE player_vehicles;ESX: owned_vehicles
The main columns in ESX Legacy:
| Column | Content |
|---|---|
owner |
The player's ESX identifier |
plate |
The plate, unique per car |
vehicle |
A JSON text with the vehicle properties |
type |
car, boat, aircraft... |
stored |
1 in the garage, 0 out in the world |
job |
Set for job vehicles, otherwise empty |
Garage scripts add their own columns, for example for the garage name or a pound state.
QBCore and QBox: player_vehicles
| Column | Content |
|---|---|
citizenid |
The character that owns the car |
license |
The player's license identifier |
vehicle |
The model name |
hash |
The model hash |
mods |
A JSON text with the vehicle properties |
plate |
The plate |
garage |
The garage id the car belongs to |
state |
0 out, 1 garaged, 2 impounded |
fuel, engine, body |
Last saved values |
QBox uses the same table with the same ideas. Other columns, like finance data, vary.
Properties as JSON
The vehicle column on ESX and the mods column on QBCore hold the appearance and tuning of the car as JSON: colours, mods, wheels, plate, extras, neon, and so on. A garage reads it when you take the car out, and writes it again when you store it.
-- when storing, on the client
local props = lib.getVehicleProperties(vehicle)
TriggerServerEvent('my_garage:store', plate, json.encode(props))The JSON must be valid. If a script wrote a broken string, the car cannot be restored and spawns stock or not at all. The article on vehicle properties shows how to build and apply them.
Vehicles missing from the garage
Run these in order.
1. The row exists but belongs to someone else
The garage list filters by owner. If the owner value is not the one the server uses for your character, the row is invisible:
SELECT owner, plate, stored FROM owned_vehicles WHERE plate = 'MIC 001';SELECT citizenid, license, plate, state FROM player_vehicles WHERE plate = 'MIC 001';Compare the owner with your real character:
- ESX: the identifier in
users.identifierfor that character. With a multicharacter script it can carry a prefix such aschar1:, and a vehicle bought before you installed multicharacter has the old value without it. - QBCore and QBox: the
citizenidin theplayerstable.
After a framework change, an import from another server or a manual insert, this is the most common cause. Fix it by pointing the row to the right value:
UPDATE owned_vehicles SET owner = 'char1:abcdef...' WHERE plate = 'MIC 001';
UPDATE player_vehicles SET citizenid = 'ABC12345' WHERE plate = 'MIC 001';Replace the values with the real ones from your tables.
2. The state is stuck "out"
A car that you took out and that never came back, for example after a crash or a restart, stays marked as out. The garage only lists stored cars.
ESX, set the stored flag back:
UPDATE owned_vehicles SET `stored` = 1 WHERE `stored` = 0;QBCore and QBox, set the state to garaged:
UPDATE player_vehicles SET state = 1 WHERE state = 0;Warning: on a live server this also stores cars that players are driving right now. Run it at startup, or limit it with a
WHEREon one plate or one owner.
Many servers run a cleanup like this automatically when the resource starts, since after a restart no vehicle can still be out. If yours does not, you can do it yourself:
-- server side, runs when the garage resource starts
AddEventHandler('onResourceStart', function(resource)
if resource ~= GetCurrentResourceName() then return end
MySQL.update('UPDATE player_vehicles SET state = 1 WHERE state = 0')
end)Note the backticks around stored in the ESX query: stored is a reserved word in MySQL and fails without them. Some scripts then send these cars to an impound state instead of the garage, so check what your garage expects.
3. The garage id does not match
On QBCore the garage column says which garage the car lives in. A garage named in your config that is not in the row, or a renamed garage, shows nothing. List the values in use:
SELECT garage, COUNT(*) FROM player_vehicles GROUP BY garage;Set the cars to a garage that exists in your config.
4. The car type does not match
Garage scripts separate cars, boats and aircraft by the type column or the vehicle class. A boat saved as car never shows in the boat garage.
Plates
The plate links the world, the database and the keys. Keep these rules:
- The plate is unique per row. A duplicate causes the wrong car to load.
- The plate is at most 8 characters in the game, the column can be longer on ESX.
- Spaces count.
MIC 001andMIC001are two plates, so use one format.
For keys, see vehicle keys.
Add a car to a player by SQL
You can give a vehicle by inserting a row. Take the column list from your own DESCRIBE, since a missing required column makes the insert fail:
INSERT INTO owned_vehicles (owner, plate, vehicle, type, `stored`)
VALUES ('identifier-here', 'MIC 001', '{"model":-1130810103,"plate":"MIC 001"}', 'car', 1);The model in the JSON is the model hash, not the name. Your framework or your garage usually has a command or a function that does this properly, which is the safer way when it exists.
Checklist
| Symptom | Fix |
|---|---|
| Garage says no vehicles | Check that owner or citizenid matches your character |
| Car stuck out after a crash or restart | UPDATE the stored flag or state back to garaged, ideally at startup |
| Bought car does not show | Check the row exists, the owner, and the garage or type |
stored query gives a syntax error |
Put backticks around stored |
| Car loads without mods | Check the vehicle or mods JSON is valid and not empty |
| Wrong car loads | Look for duplicate plates |
| Boat or aircraft missing | Check the type column matches the garage |
Quick answers
Why is my car not in the garage?
Either the row is not linked to your character (wrong owner or citizenid), or the car is marked as out. Check the owner column and the stored or state column in the database.
What does state mean in player_vehicles?
On QBCore and QBox, state is a number: 0 means the car is out in the world, 1 means it is stored in a garage, 2 means it is impounded. A car stuck at 0 does not show in the garage list.
How do I put every car back in the garage?
Run one UPDATE that sets the stored flag or state to the garaged value for the rows that are out. It is best to run it at server start, since no car can really be out after a restart.
Scripts that skip this problem
Advanced BoostingTablet-driven vehicle boosting: contracts from class D to S+, crews and a live queue.View script →
Chameleon Paints82 colour-shifting chameleon paints in one click-to-apply menu.View script →
Car BombPlant, detect and defuse vehicle bombs — with a detonator phone and a C4 minigame.View script →