dxlorean
(dxlorean)
March 24, 2021, 11:26am
#1
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
Ok6c
(Ok6c)
March 24, 2021, 11:30am
#3
“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
dxlorean
(dxlorean)
March 24, 2021, 11:30am
#4
Oh i understood, i just found an older Thread
It’s pretty simple , just keep the surfacegui in StarterGui and set it’s .Adornee property to whatever part you like.
This way you can locally get the player who’s clicking the button
I put the SurfaceGui inside the StarterGui and set the Adornee to the part, works fine!
1 Like