Looping through parts in numerical order

INTRO

im currently working on a little cutscene system thing for my 3-year development hell game and im obviously having a problem with it as you could probably imagine with the title.


ISSUE!!

for the sake of simplicity im not gonna get too into detail how this works, so ill just talk about the main problem itself

i have this folder which has cutscenes inside of them, which include camera angles. as we can clearly see from first glance something is wrong with the order of them

i want the angles’ names to be in order of their angle number so that when the cutscene module starts looping through a cutscene, it can match the index and angle number to run the necessary code.
image

i have attempted using the table.sort thing, but even then it continues to leave it as is (probably because it uses the same system to place them in alphabetical order) and this is where the real issue begins


(ignore the blurred comments, they dont really matter here lol)

the code i wrote is supposed to loop through the data of a cutscene (its angles) and run code in conjunction to whats provided within the angle, normally when no 10th angle is involved, everything is fine. but for some reason “angle10” causes the cutscene to end abruptly because the number 10 does not match the index, which would be 2.


closing words

i’d love to know if theres any solution to this number sorting error, because ive looked everywhere (at least with what i could find) and no one else seems to be having any problem similar to mine.

i’m thinking it has something to do with table.sort, because it does work, thats for sure, just not in the way id like it to

but yea, let me know what you guys got, thanks a lot in advance!

1 Like

Because all of the children of the cutscenes folders are BaseParts, you can just approach it like this.

for _, folder in pairs(Cutscenes:GetChildren()) do
    for i = 1, #folder:GetChildren() do
        print("angle"..i)
        local anglePart = folder["angle"..i]
        -- set camera to this anglePart's CFrame or something
    end
end
2 Likes

you could just do:

local Angle = Cutscenes.intro["angle"..i]

or

local Angle = Cutscenes.intro:FindFirstChild("angle"..i)
1 Like