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:
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
local block = workspace.NAMEOFBLOCKHERE script.Parent.Adornee = block script.Parent.BUTTON.MouseButton1Down:connect(function() print(game.Players.LocalPlayer.Name) end)
gg no re
Use a LocalScript, perhaps in Backpack, or PlayerGui
local player = game.Players.LocalPlayer local surfaceGui = player.PlayerGui.SurfaceGui local block = Workspace.Block surfaceGui.Adornee = block surfaceGui.TextButton.MouseButton1Up:connect(function() -- Do Stuff -- 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:
script.Parent.MouseClick:connect(function(player) print(player.Name .. " pressed me!") end)