shared
DoesEntityExist
FiveM shared native documentation with a Lua example.
Summary
Checks whether an entity handle still refers to a real, existing entity. Essential before using any handle that could be stale (networked entities, spawned vehicles, deleted objects).
Returns
boolean — true if the entity exists.
Parameters
entitynumberThe entity handle to check.Example
local veh = NetworkGetEntityFromNetworkId(netId)
if DoesEntityExist(veh) then
SetVehicleNumberPlateText(veh, 'OK')
endCommon pitfalls
- Always check this before acting on a handle you got from a network ID or stored earlier — handles go stale.
- A handle of 0 never exists; this catches that and deleted entities too.
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 →