How to check which player clicked on a SURFACE GUI TEXT BUTTON

How to check which player clicked on a surface gui text button?

For example: We have a surface gui text button whereas if we click, then the .MouseButton1Click function will be fired (which can be done by enabling BillboardGui.AlwaysOnTop)

And here is my question, how do you check which player has fired the .MouseButton1Click function?

Any help is appreciated :slight_smile: !

.MouseButton1Click:Connect(function(Plr)

end)

Plr would be the player that clicks it

image
It doesn’t even return any parameters, so this wouldn’t work.

Is the button server or client side?

Server side. (although you can easily do it client side by using game.Players.LocalPlayer)

Hmm, weird, when I use connect functions on the server side I normally use function(Plr) to get the player which fired it…

1 Like

Thats remote events, not text buttons.

If you need it specifically on server:
What you could do is hook up a ClickDetector and use the MouseClick event of that instance on the server which passes the Player as the first argument.

Otherwise, if it is on client, you could simply reference the LocalPlayer inside the MouseButton1Click event.

1 Like

all gui that you interact with has to be client side i believe. GUI buttons arent clickable on server end.

I have thought of that, but it would be a hassle to make since i’d have to make an invisible part

Im talking about surface gui text buttons, read my post to learn more.

How so? A surface GUI object requires an Adornee ( a part ).

1 Like

yes, surface gui buttons are still held on the client
aside from visuals. (I have been messing with this issue myself, and best i have found is to have a surface gui in your starter gui and just set adornee to the part you want)

1 Like

I’ve just tested it myself and it works just fine if you use the ClickDetector on a part with Surface GUI on any face of the part.

I know, but what if there were multiple buttons? Would i have to create multiplier parts?

Oh you’re looking for buttons, well, then I suggest you fire a remote to the server when they click it on the client, signaling that they clicked it.

1 Like

I know but what if the buttons get re-created every 10 seconds for example? (buttons getting deleted then created)

Couldn’t you just hide them instead? it sounds like a lot more work to keep track of constantly spawning items

That’s just bad practice. You shouldn’t be having “what-ifs”, you need to know what your code does, and if it requires you to constantly re-instatiate your UI then you need to think twice about the path you’re taking.

If that wasn’t obvious, i need to know that because im trying to do that in game.