There isn’t really much explaining what is going on in this post, you can’t just drop your code and wait for someone to give you code that will work. Could you please tell us what the Dummy is suppose to do and what it is doing? It is also hard to tell from the image what is going on, a little video clip would have been better. If you can let us know these few things I and I’m sure others would be happy to help!
One thing I do see in your code though is it looks a little repetitive, I recommend using for loops (specifically ipairs) to shorten down your code and make it easier not only for others to read, but for you as well. It can really help shorten down your code and help you find ways to fix your code.
I am trying to make the NPC walk down the track and cause damage but it walks into the invisible wall (That prevents players ruining its movement). I tried to toggle the Part1 and Part2 Positions but no difference.
“This code sample includes a function that avoids the 8 second timeout on Humanoid:MoveTo by calling Humanoid:MoveTo again before the timeout elapses. It also includes an optional andThen parameter where developers can pass a function to be called when the humanoid reaches its destination.”
What they are saying is after 8 seconds Humanoid:MoveTo() will be cancelled and Dummy.MoveToFinished will be called.
To fix this you would need to repeatedly call Humanoid:MoveTo() with this function:
local function moveTo(humanoid, targetPoint, andThen)
local targetReached = false
-- listen for the humanoid reaching its target
local connection
connection = humanoid.MoveToFinished:Connect(function(reached)
targetReached = true
connection:Disconnect()
connection = nil
if andThen then
andThen()
end
end)
-- start walking
humanoid:MoveTo(targetPoint)
-- execute on a new thread so as to not yield function
spawn(function()
while not targetReached do
-- does the humanoid still exist?
if not (humanoid and humanoid.Parent) then
break
end
-- has the target changed?
if humanoid.WalkToPoint ~= targetPoint then
break
end
-- refresh the timeout
humanoid:MoveTo(targetPoint)
wait(6)
end
-- disconnect the connection if it is still connected
if connection then
connection:Disconnect()
connection = nil
end
end)
end