local NPC = script.Parent
local humanoid = NPC.Humanoid
local Doors = game.Workspace.DoorTarget
for i, door in ipairs(Doors) do
local distance = (NPC.PrimaryPart.Position - door.Positon).magnitude
if distance < maxDistance then
nearestDoor = door
maxDistance = distance
end
end
if nearestDoor then
humanoid:MoveTo(nearestDoor.Position)
end
Hi All,
I have made this script above, basically I have an NPC that needs to go to the closest "DoorTarget" block, and once done should go to the next closest "DoorTarget" and this should this continue. The max distance needs to be 20
For some reason this script doesn't want to work, please let me know if you can find this issue.
FYI: I just place this script inside my NPC
Thanks in advance all..

2 comments
Thanks for the response, I seem to be getting this error? " 01:56:31.690 Workspace.NPC.Script:7: invalid argument #1 to 'ipairs' (table expected, got Instance) - Server - Script:7"
Ah sorry, editing my answer now