GetDistanceBetweenPlayers
Jump to navigation
Jump to search
getDistanceBetweenPlayers
Calculates the latest known 3D distance between two players.
Syntax
number getDistanceBetweenPlayers(int firstPlayerId, int secondPlayerId)
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
firstPlayerId |
int |
yes | The first connected player. |
secondPlayerId |
int |
yes | The second connected player. |
Returns
Returns the distance in metres, or false when either position is unavailable.
Examples
Send a message when two players are nearby:
local distance = getDistanceBetweenPlayers(playerId, otherPlayerId)
if distance and distance <= 10 then
outputChatBox("The other player is nearby", playerId)
end
Notes
- Available only in server-side resource scripts.