FindFirstChildWitchIsA() is not giving me the first child, its giving me the newest

for some reason its giving me the newest child and not the oldest one, can anyone help?
Thanks

I believe this will just return the first child Roblox finds not the newest or oldest

how do i get the oldest then? im not sure how to do that

You can add an attribute to every child that you create that specifies the exact time of its creation, then call :GetChildren() on the parent and, using a custom sort function, sort the table that is returned from oldest to most recent. Indexing that table with 1 will then get you the oldest (first) child.

2 Likes

You could create an array and then use table.insert every time you create an instance. Then you can just loop through this array and everything will be in order

1 Like

don’t rely on FindFirstChild ordering, it isn’t defined and results in very unreliable code when trying to use it to get an instance in a specific way

<PARENT_PATH>:GetChildren()[1]

gives you the first

1 Like

i did try that but for some reason it didnt work??? ive used that before so ik what it does but i cant get it to work in this situation, ill try some stuff later im busy

i tested it and it works


image

ok well i found out why. Im destroying that child and i need to find the next oldest child. So instead of doing this is there any other way to destroy the oldest child?

local children = Instance:GetChildren()
local lastChild = children[#children] -- the instance in the table with the last index

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