Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Get Player who Clicked from button in SurfaceGui?

Asked by
bbissell 346 Moderation Voter
10 years ago

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

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

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)
Ad

Answer this question