Hi developers, I’m making this object move around following a set of waypoints. I have that part done, but after the object has reached the last way point, I want it to go back to the start and carry on. Script;
local mover = script.Parent
local waypoints = workspace.waypoints
for waypoint=1, #waypoints:GetChildren() do
mover.Humanoid:MoveTo(waypoints[waypoint].Position)
mover.Humanoid.MoveToFinished:Wait()
end
local mover = script.Parent
local waypoints = workspace.waypoints
for waypoint=1, #waypoints:GetChildren() do
if waypoint > #waypoints then
waypoint = 1
else
mover.Humanoid:MoveTo(waypoints[waypoint].Position)
mover.Humanoid.MoveToFinished:Wait()
end
end
local mover = script.Parent
local waypoints = workspace.waypoints
for waypoint=1, #waypoints:GetChildren() do
if waypoint > #waypoints:GetChildren() then
waypoint = 1
else
mover.Humanoid:MoveTo(waypoints[waypoint].Position)
mover.Humanoid.MoveToFinished:Wait()
end
end
local mover = script.Parent
local waypoints = workspace.waypoints
local idx = 1
while true do
local num = #waypoints:GetChildren()
if idx > num then idx = 1 end
mover.Humanoid:MoveTo(waypoints[idx].Position)
mover.Humanoid.MoveToFinished:Wait()
idx += 1
end