Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

3 comments

0

ahhhh i knew it was something like that - thanks bro

0

well i would recommend using repeat becuse its a forever loop and you will only be able to move one point

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.