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 10 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
10 years ago

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.

0
That's not what I had in mind... this is a tycoon... ChipioIndustries 454 — 10y
0
Regardless, using the PlayerGui is the *only* way to tell who is using the GUI. adark 5487 — 10y
0
Ok. ChipioIndustries 454 — 10y
Ad
Log in to vote
0
Answered by
wazap 100
10 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

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

gg no re

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

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.

Log in to vote
-1
Answered by 10 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:

script.Parent.MouseClick:connect(function(player)
    print(player.Name .. " pressed me!")
end)
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 — 10y

Answer this question