ExampleArray = {
[1] = TextButton,
[2] = TextButton2
}
for i, TextButtons in pairs(ExampleArray) do
TextButtons.MouseButton1Down:Connect(function()
print("click")
end)
end
EDIT: i did a quick test and it works! I can press 2 buttons using only one event.
This is to make sure you are reffering to the textbutton…
Another thing to note: the script i used to test was in StarterGui.
This could potentially explain the issue
Just noting, you would want to store the ScriptSignal in another array for when you want to disconnect them.
A more lightweight approach however, would be to detect user input of the mouse and then checking if they pressed a button using BasePlayerGui:GetGuiObjectsAtPosition. Personally this is my preferred method, as you don’t have to continually connect and disconnect button events. Instead you just need to create a very simple UI state system with a state tracker. Then you can store the button elements in a dictionary with their function and just call that function.
I noticed a flaw in this code only now. This only seems to work for one of the buttons in the array. Is the same happening to you? Any ideas how to fix this?
Yes everything in the array is correct. I’ve switched over to using @BuilderBob25620 's method now which works fine. And as he stated it should be more lightweight. Thanks anyway.