Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Who clicked my TextButton?

I have a textbutton on an object in the world which I'm binding MouseButton1Clicked events to. How do I tell who clicks it?

1 comment

0

It's a simple question, but one which most people using textbuttons will run into, and there is no indication of how to do it in the documentation I've been able to find so far.

2 answers

As the SurfaceGui wiki page says, SurfaceGuis must be descendants of PlayerGui in order to know the player who is interacting with it.

Your best bet would be to put the GUI inside of each player's PlayerGui, and set the Adornee to the original object.

Hope this helped.

2 comments

0

I though everyone knew that. Probably needs to watch a few tutorials.

0

Ah thanks. It's a bummer. Right now I have clickable bricks, with sGuis on them explaining what each one does. I was hoping that I could just add a TextButton to the sgui instead of the current TextLabel's i'm using, and then get rid of clickdetectors. (The goal being to make only one face of the brick clickable instead of the whole thing)

-- Wherever your text button is
workspace.TextButton.MouseButton1Down:connect(function(Player)
	local PlayerName = Player.Name
end)

That code will give you the name of the player who clicks the button.

2 comments

0

No, it wouldn't. The MouseButton1Down event passes the x and y positions of where the input occurred as arguments, not the player. http://wiki.roblox.com/index.php?title=API:Class/GuiButton/MouseButton1Down

0

Oh, jeez whoops. Was thinking ClickDetectors XD my bad. (Not much of a GUI person)

This discussion is preserved as it was. New answers, comments, and votes are closed.