As I expand my game, my scripts are getting... too long, and I don't want to type in event:Connect(function() for each Gui Button, How would I avoid this? For Instance, this is how I want it to work:
--Menu = "ScreenGui"
--(LocalScript in StarterGui)
for i = 1,20 do
Button = Instance.new("TextButton")
Button.Name = "Button"..i
Button.Parent = script.Parent
end
for i, v in pairs(script.Parent.Menu:GetChildren()) do
-----------------------------EVENT-------------------------------------------------
v.MouseButton1Click:Connect(function()
print("Yay!")
end
end
This is a rough example, but this is how I want it to work, each event is going to export the button number to a function called "Save", and I do not have to type in every one.

5 comments
In the real script, do these buttons do different things?
yes
I would like them to go to the same function, but as a argument each one gives a different number, and I decode it in the function I connect them all to
Filter out using their name? If v.Name == "GuiName" then (your code) elseif v.Name == "OtherGuiName" then (your code) end
Im pretty sure I will just duplicate scripts, have a values inside of them, and change the value for each increment, and send it all to an event.