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
Untested.
Hi, so I tested, doesnt seem to work the best, the output just says this,
Workspace.Cleaner.Script:5: attempt to get length of a Instance value
May I ask you what workspace.waypoints is?
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
1 Like
So do you mean after it reached the last waypoint it follows the waypoint in reverse(instead of 1 to 2 its 2 to 1)
I found the issue to be where I had too many waypoints so there was proably too much data. I dont know how it works but yea.
1 Like