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

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

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

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.

1 comment

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.

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