Is there a way to detect a gui button clicked using a script

sorry about the little misdirection lol! but I wanna know how to use the script “detector” to detect if the button was clicked:
screenshot

4 Likes

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

You should be using a local script as gui interaction is client sided

1 Like

Use MouseButtonDown1 instead for detecting both mobile & PC input, I personally don’t use MouseButton1Click

For the OP, you can also get through all the objects of the Gui calling GetDescendants(), checking if the object is a GuiButton or not to trigger the event:

local Gui = script.Parent

for _, Object in pairs(Gui:GetDescendants()) do
    if Object:IsA("GuiButton") then
        Object.MouseButton1Down:Connect(function()
            print(Object.Name.." was pressed")
        end)
    end
end
7 Likes

Use a LocalScript and do this

local Btn = --location of your button here
local plr = game.Players.LocalPlayer
Btn.MouseButton1Click:Connect(function()
 print(plr.Name..' has clicked the button!')
end)
2 Likes