Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Humanoid:MoveTo seems to not work with slow speed NPCs?

Asked by 3 years ago
Edited 3 years ago

So i have a script that makes an NPC walk to certain waypoints then destroy itself, here's the script:

01-- Waypoint Folder and Parts
02local Waypoints = game.Workspace.Map.Waypoints
03local Way1 = Waypoints:WaitForChild('Waypoint1')
04local Way2 = Waypoints:WaitForChild('Waypoint2')
05local Way3 = Waypoints:WaitForChild('Waypoint3')
06local Way4 = Waypoints:WaitForChild('Waypoint4')
07local Way5 = Waypoints:WaitForChild('Waypoint5')
08local Way6 = Waypoints:WaitForChild('Waypoint6')
09 
10-- Self
11local Self = script.Parent.Parent
12local hum = Self:WaitForChild('Humanoid')
13local Walk = hum:LoadAnimation(Self:WaitForChild('Walk'))
14 
15-- Move the Humanoid; Args > HumanoidRootPart + Waypoint Part
View all 31 lines...

I use this script in many different NPCs (a fast walking one and a normal speed one) and it works fine until I put this script in a slow walk speed NPC. It moves to the first couple waypoints semi-fine but when it reaches the 3rd waypoint it goes half way and skips straight to the 5th. Any help is appreciated thanks!

1 answer

Log in to vote
1
Answered by 3 years ago

The reach goal state of a humanoid will timeout after 8 seconds if it doesn’t reach its goal. This is done so that NPCs won’t get stuck waiting for Humanoid.MoveToFinished to fire. If you don’t want this to happen, you should repeatedly call MoveTo so that the timeout will keep resetting.

The same link also has the code you'd require. Check the link if you need more context.

01local function moveTo(humanoid, targetPoint, andThen)
02    local targetReached = false
03 
04    -- listen for the humanoid reaching its target
05    local connection
06    connection = humanoid.MoveToFinished:Connect(function(reached)
07        targetReached = true
08        connection:Disconnect()
09        connection = nil
10        if andThen then
11            andThen()
12        end
13    end)
14 
15    -- start walking
View all 40 lines...
Ad

Answer this question