GetPlayerFromServerId
Docslocal retval = GetPlayerFromServerId(serverId)Description
Gets a local client's Player ID from its server ID counterpart, assuming the passed serverId exists on the client.
If no matching client is found, or an invalid value is passed over as the serverId native's parameter, the native result will be -1.
It's worth noting that this native method can only retrieve information about clients that are culled to the connected client.
Parameters
| Name | Type | Description |
|---|---|---|
serverId | int | The player's server ID. |
Quick Snippet: Get Player→ Player
→ PlayerUse this to get the local player ID or a target player's server ID.
-- Get the local player index (client-side)
local playerId = PlayerId()
-- Get the local player's server ID (for server events)
local serverId = GetPlayerServerId(playerId)
print("Player ID: " .. playerId)
print("Server ID: " .. serverId)
-- Get player ped from a server ID:
-- local targetPed = GetPlayerPed(GetPlayerFromServerId(targetServerId))Returns
PlayerReturns a player handle/index.
Examples
Official
--We will assume the serverId is '4' in this scenario and that it's a valid serverId.
-- Passing invalid Player IDs such as 'nil' or IDs that don't exist will result in playerId being -1.
local playerId = GetPlayerFromServerId(serverId);
-- If the resulting playerId is not invalid (not equal to -1)
if playerId ~= -1 then
-- Do our stuff on this player.
end