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.