Get nearest person

Hey guys!
How do i possibly get the nearest player from my position?

Loop through each player position for distance. I’m on a phone so here’s some pseudo code

Local dist
Local closeply
Local vect = Vector(5,6,7)
For k, v in pairs(player.getall()) do
If dist == nil || v:GetPos():Distance(vect) < dist then
dist = v:GetPos():Distance(vect)
closeply = v
End
End

Thanks!