Skip to main content

GetClosestPlayer

ESX.Game.GetClosestPlayer(coords)

This function gets the closest player client id, and distance to the player.

Argument

ArgumentData TypeOptionalDefault ValueExplanation
coordstable&vector3Yes(your player ped coords)Coords to search at

Example

local closestPlayer, closestPlayerDistance = ESX.Game.GetClosestPlayer()

if closestPlayer == -1 or closestPlayerDistance > 3.0 then
ESX.ShowNotification('There\'s no player near you!', 'error')
else
ESX.ShowNotification(('Found %s, they are %s unit(s) away'):format(GetPlayerName(closestPlayer), closestPlayerDistance), 'success')
end