Mouseclick on new added childs dont work

Im trying to make an Inventory System and i have one script looks like that:

for i,v in pairs(UI.Scroll:GetChildren()) do
v.MouseButton1Click:Connect(function()
print(“A”)
end)
end

but that only works on frames that are already there.
now i want to know how i could make it that it works on new added ones to

1 Like

Try this

function Click()
     print(“A”)
 end
for i,v in pairs(UI.Scroll:GetChildren()) do
    v.MouseButton1Click:Connect(Click)
end
UI.Scroll.ChildAdded:Connect(function(v)
    v.MouseButton1Click:Connect(Click)
end)