For loop not following the correct order?

I have a waypoint system and each waypoint has a number as its name, but when I run the script, they just walk to whatever waypoint they want to instead of the correct order

Video proof:
https://i.gyazo.com/aba81bd13f6312fa51d00c575fe89c75.mp4

Code:

for i,v in ipairs(waypoints) do
	humanoid:MoveTo(v.Position)
	humanoid.MoveToFinished:Wait()
end

Order of the waypoints (their names):

1 Like
for i,v in ipairs(waypoints) do 
      humanoid:MoveTo(waypoints[tostring(i)].Position)
	humanoid.MoveToFinished:Wait()
end

I don’t know why you deleted your post but that worked, thank you. I don’t know why I hadn’t thought of this solution before

1 Like

My bad I thought I made a mistake

well what you sent specifically wasn’t correct because of the waypoints variable, but that’s how i fixed in case anyone has the same issue:

local waypoints = workspace.Waypoints
for i,v in ipairs(waypoints:GetChildren()) do 
      humanoid:MoveTo(waypoints[tostring(i)].Position)
	humanoid.MoveToFinished:Wait()
end

Yea that’s the reason why I deleted the post because I thought you were using pathfinding. xD

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.