function GetClosestPlayerRadius(radius) local players = GetPlayers() local closestDistance = -1 local closestPlayer = -1 local ply = PlayerPedId() local plyCoords = GetEntityCoords(ply) for index,value in ipairs(players) do local target = GetPlayerPed(value) if(target ~= ply) then local targetCoords = GetEntityCoords(GetPlayerPed(value), 0) local distance = #(targetCoords - plyCoords) if(closestDistance == -1 or closestDistance > distance) then closestPlayer = value closestDistance = distance end end end if closestDistance ~= -1 and closestDistance <= radius then return closestPlayer else return nil end end function GetPlayers() local players = {} for _, player in ipairs(GetActivePlayers()) do local ped = GetPlayerPed(player) if DoesEntityExist(ped) then table.insert(players, player) end end return players end