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

Why is NPC is moving to a certain place only once?

Asked by 2 years ago

I made this script so that an NPC will move to different waypoints multiple times. However, it only moves there once. Any ideas why it isn't working?

SCRIPT:

local waypoints = { game.Workspace.WayPoint, game.Workspace.WayPointb, game.Workspace.WayPointc, game.Workspace.WayPointd, game.Workspace.WayPointe, game.Workspace.WayPointf }

local chosenWaypoint = waypoints[math.random(1,#waypoints)]

local humanoid = script.Parent.Humanoid

local pos = chosenWaypoint.Position

while true do

wait(1.5)
humanoid:MoveTo(chosenWaypoint.Position)

humanoid.MoveToFinished:Wait()
wait(1.5)
humanoid:MoveTo(chosenWaypoint.Position)

humanoid.MoveToFinished:Wait()

end

1 answer

Log in to vote
0
Answered by 2 years ago

I think it is because you only chose the random way point once. It is outside of the while loop so therefore, it stays the same. For the duration of the loop, the humanoid will move to the same spot. You can simply put the randomizer code inside of the loop.

0
I also suggest to add some code that prevents the game from choosing the same way point. This is because if it randomly rolls A, there is a 1/6 chance for it to roll an A again and therefore it wouldn't move for some time. JustinWe12 723 — 2y
Ad

Answer this question