GetNearestPlayer Open Source Function

function GetClosestPlayer()
local Distance = math.huge
local Target
for i,v in pairs(Game.GetPlayers()) do
if v ~= Game.GetLocalPlayer() then
local Magnitude = (Game.GetLocalPlayer():GetWorldPosition() - v:GetWorldPosition()).size
if Magnitude < MaxDistance then
MaxDistance = Magnitude
Target = v
end
end
return Target
end

There is already Game.FindNearestPlayer(Vector3 position, [table parameters])

YEH AND I MADE IT OPEN SOURCE SO PEOPLE CAN KNOW HOW IS IT MADE