Skip to Content
ScriptingNetwork Identifier ReferenceFiveM IDs: Players, Peds, Entity Handles and Network IDs
Report an error
Open in ChatGPTOpen in Claude

Keep player identity and entity identity separate

The official ID reference  distinguishes four identifier spaces. They can all look like small integers, but their functions, lifetime and runtime context are different.

IdentifierMeaningConversion boundary
Player server ID / sourceA transient server session. Some platform prose calls it a player NetID.On the client, GetPlayerFromServerId(serverId) converts to a local player index; GetPlayerServerId(playerIndex) converts back.
Client player indexThis client’s reference to a player currently known locally.It does not exist as a corresponding server index. Do not send it to the server as a target ID.
Entity handleLocal runtime reference to a ped, vehicle or object.NetworkGetNetworkIdFromEntity(handle) converts a networked entity to its network ID.
Entity network IDCross-machine reference to a currently existing networked entity.NetworkGetEntityFromNetworkId(netId) resolves a local handle when that entity is available.

A player’s ped is an entity, not the player’s account or session. GetPlayerPed accepts the appropriate player identifier for its own runtime side. NetworkGetPlayerIndexFromPed resolves a client player index from a ped; it does not return a durable account ID.

A server player can be absent on this client

GetPlayerFromServerId returns -1 when the player is not available locally. A player-index range in an old reference is not an instruction to loop over a fixed number of slots. Iterate GetActivePlayers() for currently known client players, and use the server’s GetPlayers() for server-wide decisions.

This client diagnostic reports only a valid visible player’s ped:

local function visiblePedForServerId(serverId) if type(serverId) ~= 'number' or serverId % 1 ~= 0 or serverId <= 0 then return nil end local player = GetPlayerFromServerId(serverId) if player == -1 or not NetworkIsPlayerActive(player) then return nil end local ped = GetPlayerPed(player) if ped == 0 or not DoesEntityExist(ped) then return nil end return ped end

An absent local player is not proof that the player disconnected or that the server ID is forged. The player can simply be outside scope. The server makes authoritative session and permission decisions.

Network entities can also be out of scope

Use a network ID across machines, then check NetworkDoesEntityExistWithNetworkId(netId) before resolving it on the client. Resolve the handle and check existence again before the native operation. Network IDs can be reused after an entity disappears; a delayed response must also carry your application-level identity or generation.

A non-networked local demo entity has no useful cross-machine identity. The same networked entity can have different handles on different clients, or receive a different local handle when recreated. Neither a local handle nor a network ID is a database primary key for permanent vehicle ownership.

The source describes entity network IDs as 16-bit values during the entity’s lifetime. Do not interpret that representation as a universal future capacity promise. Server-side entity handles and meaningful network-ID round trips require state awareness; turning it off changes what server scripts can resolve.

Preserve sessions across asynchronous work

Saving the event’s source before a wait prevents event-context loss, but does not prevent another player receiving that number after disconnect. Enhanced can reuse server IDs immediately; Legacy IDs are also transient. Before a delayed reply or mutation, confirm the initiating session generation is still current and use a separately verified account identity for durable records.

Validate ownership and permission after resolving a client-supplied entity ID. Existence alone does not authorize deleting the entity, entering it, changing its inventory or receiving its private state. See secure requests, session-safe asynchronous work, and state bags.

Acceptance cases

Test a visible player, an out-of-scope player, a deleted entity, a non-networked entity, an entity that leaves and re-enters scope, an ownership migration and a reconnect that reuses a session ID. Each failure should stop the operation or take a bounded recovery path, not silently substitute the local player or entity zero. These checks require the actual client/server runtime; website tests validate the published references and examples, not the network engine.