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

How do I get the user who clicked a SurfaceGui?

Asked by 11 years ago

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?

4 answers

Log in to vote
2
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
11 years ago

You have to add the SurfaceGui to their PlayerGui, and set its Adornee property, like so:

1SurfaceGui.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.

0
That's not what I had in mind... this is a tycoon... ChipioIndustries 454 — 11y
0
Regardless, using the PlayerGui is the *only* way to tell who is using the GUI. adark 5487 — 11y
0
Ok. ChipioIndustries 454 — 11y
Ad
Log in to vote
0
Answered by
wazap 100
11 years ago

Use what adark said.

Put the SurfaceGui in StarterGui, then set Adornee to brick. Then in a LocalScript in the Gui do this

1local block = workspace.NAMEOFBLOCKHERE
2script.Parent.Adornee = block
3script.Parent.BUTTON.MouseButton1Down:connect(function()
4print(game.Players.LocalPlayer.Name)
5end)

gg no re

Log in to vote
0
Answered by
hiccup111 231 Moderation Voter
11 years ago

Use a LocalScript, perhaps in Backpack, or PlayerGui

01local player = game.Players.LocalPlayer
02 
03local surfaceGui = player.PlayerGui.SurfaceGui
04 
05local block = Workspace.Block
06 
07 
08surfaceGui.Adornee = block
09 
10 
11surfaceGui.TextButton.MouseButton1Up:connect(function()
12 
13    -- Do Stuff --
14 
15end)

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.

Log in to vote
-1
Answered by 11 years ago

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:

  • Part -- SurfaceGui --- TextButton/TextLabel -- ClickDetector --- Script

The script inside of the ClickDetector would look something like this:

1script.Parent.MouseClick:connect(function(player)
2    print(player.Name .. " pressed me!")
3end)
0
You can parent the SurfaceGui to the Player's PlayerGui (For example, by putting it in the StarterGui) to allow the scripts to know that that specific Player is using the SurfaceGui. adark 5487 — 11y

Answer this question