Possible to detect a mouse click like this? (without copy pasting)

Hi people of the World!

I was wondering if there was a way to detect if anyone of many text buttons are clicked (without copy pasting)

let’s say you have a frame, with like 20 buttons, is it possible to detect if one of those are clicked
(and see what the name of the text button is)


I’m guessing this is gonna be coroutine type thing, not sure!

(thx)

MouseButton1Click – used in a local script.

https://developer.roblox.com/en-us/api-reference/event/GuiButton/MouseButton1Click

If you’re using a local script, then you may want to try this:

for _, v in pairs(parent:GetChildren()) do
    v.Activated:Connect(function()
        print(v.Name) -- Button clicked
    end)
end
1 Like

no lol, I know that you can detect if one button is pressed, but can I detect if one of many is clicked?

2 Likes

yeah I was thinking about that, I haven’t tried it yet, I’ll give it a shot!

Make a loop that iterates through each of the buttons and then connect the click for v to whatever you want it to do.

If you want to disconnect the button connection after one of the buttons being clicked, you can make a table and insert the button functions there, then upon being clicked, run a loop and disconnect the functions, maybe even store the button name that was clicked in a local variable, well if that’s what you need.

Okay yeah, it worked!

Had to change it a bit to match my layout but it’s all good, thanks!

1 Like