Issue with for loop randomly inserting objects

I have a folder with animations.

2

I am using a for loop to insert each animation into a table.

local Assets = game:GetService("ReplicatedStorage"):WaitForChild("Assets")
local Street = {}
for _, Folder in pairs(Assets.Animations:GetChildren()) do
	for _, Animation in pairs(Folder:GetChildren()) do
		
		if Animation.Name:find("StreetA") then
			table.insert(Street, Animation)	
		end
	end
end
print(Street)

They are not being inserted in the order that they are in the folder.

Upon each game startup, they are randomly oriented into the table, different every time.

Is there any fix for this? I need the animations to be in order because
they are part of a combat system.

Just re-sort them manually by removing everything from the folder and then manually sorting them in by the order you want

They are sorted in the order I want. The problem is, when the for loop takes what’s in the folder and iterates them into a table, they come out random.

local Assets = game:GetService("ReplicatedStorage").Assets
local Street ={}

for _, Folder in Assets:GetChildren() do
	for i = 1, #Folder:GetChildren() do
		for _, Animation in Folder:GetChildren() do
			if Animation.Name:find("StreetA"..i) then
				table.insert(Street, Animation)
			end
		end
	end
end
print(Street)
1 Like

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