It's tiring to make a function for each one to check if it was clicked. Is there another way to go about doing this? Maybe something like a loop.
Yes, you would go with a for loop.
LocalScript
for _,v in pairs(frame:GetChildren()) do if v:IsA("ImageButton") then v.MouseButton1Click:Connect(function() -- Fire server or do other code end) end end
for i, v in pairs(script.Parent:GetChildren()) do --assuming it's in the startergui, and it's a localscript of course if v.ClassName:lower():match("button") then --might be wrong, haven't done lua in a while v.MouseButton1Click:connect(function(egg) --code end) end end
Tell me if something errored. I haven't used lua in a while