QueryDescendants display order

Just a quick question. I need to filter children of an Instance of a specific class. Thus I’m using QueryDescendants() to achieve that. Now I want to delete the “oldest” child of all of the found instances. I know that GetChildren() automatically sorts from oldest to newest, but I’m not sure about QueryDescendants. does it?

local parent = workspace.Example
local children = parent:QueryDescendants("Class")
print(children[1].Name) -- is this the "oldest" child?

doing and testing this makes it look like it does actually query the oldest child but it is just very important that i ensure it actually is and doesnt have to do with any naming or other factors. any help appreciated!

Checking the documentation for GetChildren reveals that the method does not ensure consistency for the order of returned instances. This behavior likely applies to other instance “getter” methods such as QueryDescendants.

image

It’s best to manually sort the table yourself to ensure consistent behavior. For your need, you can add an attribute which stores a creation index to every new instance you create and filter results based on this concept.

smart way of doing it. thank ya mate

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