It may be because you are doing this on the client and things are replicated to the client. So it has a random order. Kinda hard to explain. Try the same code on the server.
Another thing you can do is to write script that gets all seeds one by one in table
like it searches for seed1 then inserts it in and breaks when found
(I dont think you actually have to break loop)
You can do this with for loop
for i=1, #ReplicatedStorage.Seeds:GetChildren() do
local seedname = "Seed" .. i
if ReplicatedStorage.Seeds:FindFirstChild(seedname) then
-- do thing
end
end
Why do you need the folder to be ordered? Is it to get an ordered table?
Here’s two things you could do:
Get the children, and then sort them if you only need this to be sorted for a script.
local children = folder:GetChildren()
table.sort(children, function(aChild, bChild)
local aNum = string.match(aChild.Name, "%d")
local bNum = string.match(bChild.Name, "%d")
return aNum > bNum
end)
This is basically suggestion 1 but re-inserting them into the folder
local rStorage = game:GetService("ReplicatedStorage")
local temp = Instance.new("Folder", rStorage)
temp.Name = "Temp"
--get children
local children = rStorage.SomeFolder:GetChildren()
--parent to temp
for _, child in next, children, nil do
child.Parent = temp
end
--sort the children
table.sort(children, function(childA, childB)
local aNum = string.match(childA.Name, "%d")
local bNum = string.match(childB.Name, "%d")
return aNum > bNum
end)
--re-parent children
for _, child in next, children, nil do
child.Parent = rStorage.SomeFolder
end
Roblox sorts children alphabetically, so it may be that you need to manually sort and re-parent.
yeah i think that was the problem, i created a new folder and just added all my seed parts in there and works as i intended
i think this was because i duplicated some parts in the folder itself
The :GetChildren() method returns an unsorted array of the parents children, you can sort this array using the table.sort() function
local Folder = script.Parent
local Children = Folder:GetChildren()
table.sort(Children, function(a, b)
return a.Name < b.Name
end)
for _, Child in ipairs(Children) do
print(Child.Name)
end
Edit: I don’t know why but I didn’t see 12345koips reply, nevermind then