class Player
package fivem.client.core
A player, as seen from the client.
Two different numbers identify a player and mixing them up is the single most common source of "it works for me but not for anyone else":
- player index (
index) — a small, client-local slot number. Valid only on the machine that read it, and reused when players leave. - server ID (
serverId) — assigned by the server, identical on every machine. This is the one to send in events and store in state bags.
for (player in Player.all()) {
if (player.ped.distanceToEntity(LocalPlayer.ped()) < 20) {
trace('${player.name} is nearby');
}
}Static methods
staticall():Array<Player>
Every player this client currently knows about.
That is not everyone on the server: clients only ever see players within streaming range plus a few extras. For a server-wide list, ask the server.
staticfromServerId(serverId:Int):Player
Resolves a server ID to a local Player, or null if that player
isn't currently known to this client (out of scope, or gone).