getNearestPlayers

Finds the nearest player within the specified distance.

Parameters:

  • coords (vector3, optional): The coordinates to search from. Defaults to player's current position.

  • distance (number, optional): Maximum search distance in units. Defaults to 10.0.

Returns:

  • player (number): The nearest player ID, or nil if none found

  • distance (number): Distance to the nearest player

Example:

local nearestPlayer, playerDistance = ps.getNearestPlayers()
if nearestPlayer then
    local playerName = GetPlayerName(nearestPlayer)
    print("Nearest player: " .. playerName .. " at distance: " .. playerDistance)
end

Last updated