Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I duplicate MouseButton1Click events?

Asked by
Nootian 184
4 years ago
Edited 4 years ago

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.

0
In the real script, do these buttons do different things? niroqeo 123 — 4y
0
yes Nootian 184 — 4y
0
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 Nootian 184 — 4y
0
Filter out using their name? If v.Name == "GuiName" then (your code) elseif v.Name == "OtherGuiName" then (your code) end TiredMelon 405 — 4y
0
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. Nootian 184 — 4y

Answer this question