#why does the for pairs loop run backwards?

1 messages · Page 1 of 1 (latest)

solid granite
#

it's meant to run from 0-8, but it runs from 8-0. ive already tried ipairs.

for _, v in pairs(pathfindingFolder.spotsInLine:GetChildren()) do
    print(v)
    if v.occupied.Value == false then    
        v.occupied.Value = true
        followPath(v.Position)
        if v.Name == "0" then
            wait(3)
            script.Parent.HumanoidRootPart.CFrame = v.CFrame
        end
        return
    end
    
    if v.Name == 8 then
        print("not enough spots")
    end
end
naive halo
#

pairs doesnt go in order like that

zinc chasmBOT
#

studio** You are now Level 7! **studio

naive halo
#

You'd have to use a for i=1 loop then use the index like this:

for i = 1, pathfindingFolder.spotsInLine:GetChildren()) do
  local v = pathfindingFolder.spotsInLine:GetChildren()[i]

    if v.occupied.Value == false then    
        v.occupied.Value = true
        followPath(v.Position)
        if v.Name == "0" then
            wait(3)
            script.Parent.HumanoidRootPart.CFrame = v.CFrame
        end
        return
    end
    
    if v.Name == 8 then
        print("not enough spots")
    end
end