Getting all the new values by GetDescendants

So basiclly i have a gui that will automatically added new TextButton in a ScrollingFrame
and i use GetDescendants() to get all the button, but the problem is that it get all the button before the other script can add the TextButton in.

So i need some way get all the new TextButton that just got added. Maybe a way to loop GetDescendants()

I have tried to loop it but still doesn’t work
image

while wait() do
 	button = script.Parent.Main:GetDescendants()
	for i,v in pairs(button) do
		if v:IsA("TextButton") then
			v.MouseButton1Click:Connect(function()
-- Check what button is and fire some RemoveEvent
end

i tried to loop it with the for…do… loop but it fire the RemoteEvent like 20 times a sec cause my game to lag.

You can use the ChildAdded event to detect when there a new button has been added.

Here’s an example:

local function newChild(child) -- the child parameter is from the ChildAdded event
    if child:IsA("TextButton") then
        print('New text button!')
    end
end

gui.ChildAdded:Connect(newChild)