How do I check if a children has been clicked

local plr = game.Players.LocalPlayer
while true do
    wait()
    for i ,v in pairs(plr.PlayerGui["Build Menu"].Frame.ScrollingFrame:GetChildren()) do
        print("COOLBEFOREFIRST")
        if v.ClassName == "TextButton" then
            print("COOLFIRST")
            v.MouseButton1Click:Connect(function()
                print("COOL")
                local itemvalue = plr.PlayerGui["Build Menu"].Frame.Item.Value
                itemvalue = v.Parent.Name
            end)
        end
    end
end

So how do I check if any of the gui buttons inside scrollingframe gets clicked because this doesn’t work. The buttons will get parented later so the buttons are unknown. Please help.

2 Likes
local Player = game.Players.LocalPlayer
local Frame = Player.PlayerGui:WaitForChild("Build Menu").Frame

Frame.ScrollingFrame.ChildAdded:Connect(function(Child)
	if Child:IsA("TextButton") then 
		Child.Activated:Connect(function()
			print("Clicked")
		end)
	end
end)