Get clicking player from SurfaceGui ImageButton

How do I know what player is clicking a surfacegui ImageButton? I’m trying to make an ordering system in which only the user who is signed into the register is able to place an order with the same register.

How can I detect what player is clicking the ImageButton? I am aware that SurfaceGui doesn’t support local scripts.

All help appreciated. :smiley:

Well you could just fire a remote event and that will give you the player who is clicking it.

local player = game.Players:GetService("Players).LocalPlayer

then fire a remote containing the players name might work.

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

1 Like

It’s actually quite easy. And SurfaceGui's do support local script. Otherwise, I don’t see why it worked for me.

Image from Gyazo

Just insert a local script (the ideal place would StarterPlayerScript) and simply write the MouseButton1Click in it. Here’s what I did:

(Yep, it is indeed a TextButton but it would work with an ImageButton too.)
image

image

Local Script content:

workspace.Part.SurfaceGui.TextButton.MouseButton1Click:Connect(function()
	print("uwu")
end)

Just like others said, you could use a ClickDetector to fire a RemoteEvent, but as you mentionned that you want to do it with an ImageButton, I optted for this option.

1 Like

Ended up using Adornee.

Was hoping to have everything in the same place.

?
Not quite sure what you mean by this…

Well you do :FireServer with the remote event when the button is clicked, and then on the server, you will have to do a .OnServerEvent. The first argument of the .OnServerEvent is the player who clicked the button in this case.