I had this question for a while now, I went ahead and made a working script that does the job that I want it to do, but the problem is that it is in a loop. So everytime you press one of the buttons, the game lags for a bit, and it does what I want it to more than once, so its very annoying. I was wondering if anyone knew any other ways. Heres what I pretty much used:
while wait() do for i, v in pairs(youdontneedtoknowthislol:GetChildren()) do if v:IsA("ImageButton") then v.MouseButton1Click:connect(function() --the thing i want it to do end) end end end
thanks a lot! I appreciate any help.
You don't need the loop at all. MouseButton1Click is an event that fires every time the button is clicked regardless if it's in a loop. Here's the code you should have:
for i, v in pairs(youdontneedtoknowthislol:GetChildren()) do if v:IsA("ImageButton") then v.MouseButton1Click:Connect(function() --the thing i want it to do end) end end