I want to make this NPC move to the desired part, but before reaching the part, it stopped already? the WalkSpeed is 2. this might be the reason, but how will I fix it?
MoveTo() has a timeout of 8 seconds. Irrespective of whether or not the humanoid reaches its intended destination its MoveToFinished signal is fired. Fortunately this signal returns a Boolean value indicating if or not the goal was reached.
oh, hey i had this issue too, Maybe this function can help you
local function moveTo(humanoid, targetPoint)
local targetReached = false
local connection
connection = humanoid.MoveToFinished:Connect(function(reached)
if humanoid.Parent.HumanoidRootPart.Anchored == false and humanoid.WalkSpeed ~= 0 then
targetReached = true
connection:Disconnect()
connection = nil
print("Finished moving")
else
moveTo(humanoid, targetPoint)
end
end)
humanoid:MoveTo(targetPoint)
spawn(function()
while not targetReached do
if not (humanoid and humanoid.Parent) then
break
end
if humanoid.WalkToPoint ~= targetPoint then
break
end
humanoid:MoveTo(targetPoint)
task.wait(6)
end
if connection then
connection:Disconnect()
connection = nil
end
end)
end
I found this a long time ago, just customized by a bit