How do I find the player that clicked a GUI button

ex.

Button.MouseButton1Click:Connect(function(Clicked)
print(Clicked.Parent)
end)

Clicked does not have a parent, so I want to find a way to get it otherwise

If it’s a local script then just do

local player = game.Players.LocalPlayer

3 Likes

The MouseButton1Click automatically detects who clicked the GUI buttons for you.

It detects who clicked the button and executes the code inside it.

The code below executes the code inside the function to the player who clicked the gui button.

script.Parent.MouseButton1Click:Connect(function() --- script.Parent is the button btw
-- Code here
end)