Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Does ":GetChildren()" work in any kind of order?

So long story short I need to have a list of all the items within a certian model. So I thought Instead of looping through each item I need a list of I could just use :GetChildren(). However I need the list to be in order for another part of my code to work properly, so is there any way to get a consistent order out of GetChildren.

Ex.

-- Ik these are lists but for the sake of argument imagine each item in the list is an object inside the variable
local numbers = {1,2,3,4,5,6,7,8} 
local otherNumbers = {1,2,3,4,5,6,7,8}
local otherOtherNumbers = {1,2,3,4,5,6,7,8}

numbers:GetChildren()
otherNumbers:GetChildren()
otherOtherNumbers:GetChildren()

For instance I would want all of these to return all of the numbers in order (absolutely essential they are in order), yet for some reason, 1 might consistently return (2,3,4,5,6,7,8,1) , and Im not sure what else to do about it. Lmk if that makes sense or if anyone needs a code sample to understand what im asking.

2 comments

0

I'm not sure if theres even a kind of order in :GetChildren()

0

Well I wouldn't think so, but there has to be

1 answer

Something you might be able to do is:

local numbers = {1,2,3,4,5,6,7,8}
local children = numbers:GetChildren()

for i=1,#children do
  print(children[1])
end

A way you could test if it's in order is to create a part with multiple children in numbered order then print the children with the code above.

1 comment

0

I get the idea, and have thought about it myself, but I want to try my best to avoid using any more for loops, because in my current script I have quite a few

This discussion is preserved as it was. New answers, comments, and votes are closed.