function FindNearestPlayer(StartPlayer)
local found
for i,v in pairs(game.Players:GetPlayers()) do
local last = math.huge
local distance = v:DistanceFromCharacter(StartPlayer.Character.HumanoidRootPart.Position)
if distance < last then
found = v
end
last = distance
end
return found
end
while true do
wait(1)
print(found)
end
it returns nil

2 comments
prob because it didn't found anything
When I play in game it still doesnt idk why