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 comment
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.