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

How do I Change the MoveTo() Timeout?

Asked by
Sulu710 142
5 years ago

I'm using the MoveTo() function on a humanoid to move it on a path, from one point to another along the path. However the timeout frequently makes the humanoid move on to the next point instead of going where it's supposed to. Here's my code:

01Spawned.Humanoid:MoveTo(d1.Position)
02Spawned.Humanoid.MoveToFinished:wait()     
03Spawned.Humanoid:MoveTo(d2.Position)   
04Spawned.Humanoid.MoveToFinished:wait()
05Spawned.Humanoid:MoveTo(d3.Position)
06Spawned.Humanoid.MoveToFinished:wait()
07Spawned.Humanoid:MoveTo(d4.Position)
08Spawned.Humanoid.MoveToFinished:wait()
09Spawned.Humanoid:MoveTo(d5.Position)
10Spawned.Humanoid.MoveToFinished:wait() 
11Spawned.Humanoid:MoveTo(d6.Position)
12Spawned.Humanoid.MoveToFinished:wait()
13Spawned.Humanoid:MoveTo(d7.Position)
14Spawned.Humanoid.MoveToFinished:wait()

Spawned is the variable for the rig, and I established d1-d7 as variables as well. When this is run the default timeout of 8 seconds causes the humanoid to go to the next spot before it has gone to the current one, therefore not completing the path as it should. Is there a way to change the timeout, and if there isn't how do I make it work correctly? I am very new to this function, so I apologize if this is a dumb question. Thank you for reading!

2 answers

Log in to vote
1
Answered by
Psudar 882 Moderation Voter
5 years ago

Check this place out. At the bottom theres a script that mentions using MoveTo with no time out.

https://developer.roblox.com/en-us/api-reference/function/Humanoid/MoveTo

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
Log in to vote
0
Answered by
poke7667 142
5 years ago
Edited 5 years ago

I recommend using something else instead of spamming MoveTo called PathfindingService. This is probably what you should look into as it auto generates a path for you which will make your life easier with NPCs. Here are the docs for: PathfindingService

0
This creates a path from one place to another without touching a wall or other part, I don’t think this will be useful to move a humanoid along a path I made Sulu710 142 — 5y

Answer this question