Get a player that clicked a SurfaceGui Button

How can i get the player that clicked the SurfaceGUI button?

script.Parent.MouseButton1Click:Connect(function(player)
print(player.Name)
end)
  • i was surprised this did not work
    also, This is a Script inside a SurfaceGui inside a Part
  • i searched the Forum and all the sources i found only worked on LocalScripts
  • Local Scripts can’t operate on the server

Thanks for the help!

Set the adornee to the Part, and place the SurfaceGui in StarterGui

5 Likes

“Player” is referring to the button being pressed. You can get the player by using the PlayerAdded event.

lgame.Players.PlayerAdded:Connect(function(player)
Try adding the rest of your script inside the button click event. Remove the “Player” inside your MouseButton1Click event.

2 Likes

Oh i understood, i just found an older Thread

I put the SurfaceGui inside the StarterGui and set the Adornee to the part, works fine!

1 Like