That is my question, Does FindFirstChild are going to find the first child in a parent? If it's false answer, could it be happened? I have a script about creating TextLabel in a Frame, i'm not sure if i used FindFirstChild to delete the Oldest TextLabel. Thanks for all the people who reply/answered me.
COMMUNITY QUESTION
Are FindFirstChild exactly find the first child?
1 answer
To answer your question, yes, it will return the first one that it finds, which will usually be the newest one; this seems to be the opposite of what you want. In order to delete the oldest ones first, you'll need to use the GetChildren function and loop through the returned array backwards.
function GetOldestChildByName(parent, name)
local children = parent:GetChildren()
for i = #children, 1, -1 do
if (children[i].Name == name) then
return children[i]
end
end
return nil
end
That will get the oldest child by name from the parent, then you just have to do
child:Destroy()
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
FindFirstChild() finds the first child by the given name. If there is more than one Instance by that name, it will only return the first Instance by that name in the table.
Yes, i made them all have the same name. I wonder this could find the oldest,second oldest,third oldest...
If you're trying to remove the items by how old they are, use a table to organize the objects into a list of how old they are instead of using FindFirstChild()