So I have a bunch of buttons right now, and this is what I have to connect the same function to each of them:
for _, button in pairs (buttons:GetChildren()) do if button:IsA("TextButton") then button.MouseEnter:connect(function() button.TextSize = 21 end) button.MouseLeave:connect(function() button.TextSize = 20 end) button.MouseButton1Down:connect(function() animateTopBarButtons(button) end) end end
Is this the best way to do this, or should I connect each button separately? (which will take up a ton of lines)
If you want each of the buttons to act in the same way upon user interaction, then what you have is fine. It would probably be more robust to group the buttons together in some way, perhaps by making them children of the same parent, so you don't have to iterate over every GUI element and run
if button:IsA("TextButton") then ... end