Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Get Player who Clicked from button in SurfaceGui?

Hello,

I was wondering how to get the player who clicked a button in a SurfaceGui. A LocalScript doesnt work since its not a descendant of the player or their character. Any ideas?

1 answer

✓ Accepted answer

You can use a LocalScript, by just putting the LocalScript in the PlayerGui and making it look for game.Workspace.MyScreen.

This would work well if there was only one particular Surface that you care about (e.g., this one screen in the lobby, etc), though using loops you could also just include any number of others in the workspace.


e.g.

local surface = workspace.ScreenMain.SurfaceGui
local button = surface.Frame.TextButton

local player = game.Players.LocalPlayer

function clicked()
	print(player, "clicked")
end

button.MouseButton1Down:connect(clicked)

This discussion is preserved as it was. New answers, comments, and votes are closed.