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.
✓ ANSWER ACCEPTED
Efficient way to check for a button click when you have too many GUI buttons?
2 answers
✓ Accepted answer
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
1 comment
0
or you can use module script if it isn't in the same location.
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
god why is no one using Module Scripts. What if it isn't a children of a frame.
I definitely agree with that...module scripts are under rated.