ScriptsAboutBlogToolsKnowledge BaseReviewsFAQBasketDocsSupport
client

GetEntityCoords

FiveM client native documentation with a Lua example.

Summary

Returns the world coordinates (vector3) of any entity — ped, vehicle, or object.

Returns

vector3 — the entity's X, Y, Z position.

Parameters

entitynumberThe entity handle (ped, vehicle, or object).
alivebooleanOptional. Whether to only return coords if the entity is alive.

Example

local ped = PlayerPedId()
local coords = GetEntityCoords(ped)
print(coords.x, coords.y, coords.z)

-- Distance check between player and a point
local target = vector3(-254.1, -971.4, 31.2)
if #(coords - target) < 2.0 then
  -- player is within 2.0 units
end

Common pitfalls

  • Using #(a - b) for distance is far cheaper than GetDistanceBetweenCoords — prefer it in loops.
  • Don't run this every frame with no Wait() — it's a common cause of server lag.

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 →