while wait() do
local pla = game.Players:GetChildren()
local a = pla[1]
for i,v in pairs(pla) do
if v.Character then
local ti = (a.Character.HumanoidRootPart.Position-script.Parent.Position).Magnitude
local te = (pla[i].Character.HumanoidRootPart.Position-script.Parent.Position).Magnitude
if te<ti then
a=pla[i]
end
end
end
if a.Character then
print(a.Name)
end
end
The problem is that scripts run before the player even loads. Another person who explains how to get around this pretty well this sleitnick https://www.youtube.com/watch?v=bX8MxozRTGo