I’m trying to make it so an NPC goes to each individual part laid out in a path. The problem is it can’t find a new closest part because the part that it’s on is always going to be the closest part to it so it just stops at the first part. How can I fix that?
local nodes = workspace.Nodes
local Closest
local hum = script.Parent.Humanoid
local torso = script.Parent.Torso
local PlayerPosition = torso.Position
for i,v in pairs(nodes:GetChildren()) do
if Closest == nil then
Closest = v
else
if (PlayerPosition - v.Position).magnitude < (Closest.Position - PlayerPosition).magnitude then
Closest = v
hum:MoveTo(Closest.Position)
end
end
end