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

How do I make the script wait until the humanoid has finished moving until it moves again?

Asked by 2 years ago
Edited 2 years ago

I'm making a script that randomly moves an NPC to different points around the map; how would I implement a wait that would wait for the NPC to reach the location until it finds another location and moves there?

Here is the script (placed inside the NPC humanoid):

local humanoid = script.Parent
local points = workspace.Points:GetChildren()

while wait() do
    local randompoint = points[math.random(1,#points)]
    script.Parent:MoveTo(randompoint.Position)
end

1 answer

Log in to vote
0
Answered by 2 years ago

Well, this is a bit buggy in code- try using PathfindingService- but that's not needed, the answer is to just do humanoid.MoveToFinished:Wait()

so..

while true do
    local randompoint = points[math.random(1,#points)]
    script.Parent:MoveTo(randompoint.Position)
    script.Parent.MoveToFinished:Wait()
end
0
ahhhh i knew it was something like that - thanks bro TabooAntonioiscool 42 — 2y
0
well i would recommend using repeat becuse its a forever loop and you will only be able to move one point sne_123456 439 — 2y
0
while true do is also a forever loop, and its doing a random position from a points array, which is probably more than 1 node for moving in. jasperagent 43 — 2y
Ad

Answer this question