local range = 50
local closest
for _, child in pairs(workspace.alive:GetChildren()) do
local success, rootPart = pcall(function()
return child.Humanoid.Health > 0 and child.HumanoidRootPart
end)
if success and child ~= character then
local distance = (rootPart.Position - character.HumanoidRootPart.Position).magnitude
if distance < range then
range = 0
closest = rootPart
print(closest.Parent.Name)
end
end
end
I'm trying to get the nearest player/npc, but this is always going to give me the first player/npc listed in the "alive" folder. Any help?

2 comments
Thank you! 8)
HHAHAHHAHAHAH WHY U ANSWeRING QUESTIONS IN 2019 BRO LIK WUT BRO WUT UR DOING WITH UR TIM BRUV LIEK BROOOOO. HAHAHHA EPIC TROLE TROLE TROEL HAHASHAT ROLE TORLE LMAOF LMOAF