Child Added not working

Basically I have a script where a button is added every 3 seconds to a frame. After that I want to see which button got added, so I run a “Child Added” function to check that, and for some reason it’s not showing and no errors are outputting.
Here is the code:

local btnHolders = script.Parent.buttonHolders
local mainShop = script.Parent.mainShop
local btns = game.ReplicatedStorage:GetChildren()

for i, v in pairs(game.ReplicatedStorage:GetChildren()) do
	if v:IsA("TextButton") then
		wait(3)
		v.Parent = btnHolders
	end
end

btnHolders.ChildAdded:Connect(function(child)
	print(child.Name)
	child.MouseButton1Click:Connect(function()
		print("Clicked Button!")
	end)
end)

That’s because your code is in the wrong order; the connection is happening after all of the TextLabels are added

The connection should come before the pairs() loop

1 Like

oh ok I got it to work thanks,gwegwmhgawer
hhn

Please mark his reply as the solution, so people know it’s been solved.