ScriptsAboutBlogToolsKnowledge BaseReviewsFAQBasketDocsSupport
client

GetClosestVehicle

FiveM client native documentation with a Lua example.

Summary

Finds the closest vehicle to a set of coordinates within a radius. Used by garages, mechanics, and interaction systems.

Returns

Vehicle (number) — the closest matching vehicle, or 0.

Parameters

x, y, zfloatThe center coordinates to search from.
radiusfloatSearch radius.
modelHashHash0 for any model, or a specific model hash.
flagsnumberSearch flags (commonly 70 to include most vehicles).

Example

local c = GetEntityCoords(PlayerPedId())
local veh = GetClosestVehicle(c.x, c.y, c.z, 3.0, 0, 70)
if veh ~= 0 then
  -- found a nearby vehicle
end

Common pitfalls

  • The flags argument matters — 70 is a common catch-all; the wrong flags can exclude vehicles.
  • Returns 0 when nothing matches; always check.

Related natives

Related guides

FiveM scripts done right

Optimized, dual-framework scripts for QBCore and ESX from Viper Development — escrow protected, delivered instantly to your Cfx portal.

Browse Scripts →