I'm trying to get the name of a player when they click a SurfaceGui with a TextButton, but I have no idea how that would work. Any ideas?
You have to add the SurfaceGui to their PlayerGui, and set its Adornee property, like so:
1 | SurfaceGui.Adornee = Workspace.Brick |
This will allow you to access the Player that has clicked the SurfaceGui, but any changes a Player makes to the SurfaceGui's contents (i.e. scrolling) will only appear for them.
Use what adark said.
Put the SurfaceGui in StarterGui, then set Adornee to brick. Then in a LocalScript in the Gui do this
1 | local block = workspace.NAMEOFBLOCKHERE |
2 | script.Parent.Adornee = block |
3 | script.Parent.BUTTON.MouseButton 1 Down:connect( function () |
4 | print (game.Players.LocalPlayer.Name) |
5 | end ) |
gg no re
Use a LocalScript, perhaps in Backpack, or PlayerGui
01 | local player = game.Players.LocalPlayer |
02 |
03 | local surfaceGui = player.PlayerGui.SurfaceGui |
04 |
05 | local block = Workspace.Block |
06 |
07 |
08 | surfaceGui.Adornee = block |
09 |
10 |
11 | surfaceGui.TextButton.MouseButton 1 Up:connect( function () |
12 |
13 | -- Do Stuff -- |
14 |
15 | end ) |
Ofcourse, this will only be visible to the local player.
If you wanted it visible to other player's, you'd have to make a system that updates the information on the surface gui, for each player. Or something along them lines.
There's not really any way that I know how to do this, but it is really easy using ClickDetectors which serve close to the same purpose. Assuming that your hierarchy would look something like this:
The script inside of the ClickDetector would look something like this:
1 | script.Parent.MouseClick:connect( function (player) |
2 | print (player.Name .. " pressed me!" ) |
3 | end ) |