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

How to reference a player who clicks a GUI?

Asked by
emite1000 335 Moderation Voter
9 years ago

So I have stumbled into a problem that I cannot seem to overcome.

I need to make something happen in the PlayerGui of a player who clicks on a TextButton. I thought simply doing something like this whould suffice:

TextButton.MouseButton1Click:connect(function(player)
--stuff happens here
local scroll = player.PlayerGui.Chat --I have a GUI named 'Chat' in their PlayerGui that I created earlier.

But since this all happens inside another function, it can't reference "player" as the one who clicked for some reason. So could someone help me figure out how to reference the Player who clicks on a TextButton?

EDIT:Sorry, I forgot to clarify. This is running inside a normal script inside a model, not in a local script.

0
I guess this is why you commented on my answer. Yes, some do not have built-in arguments. Most do though. EzraNehemiah_TF2 3552 — 9y

2 answers

Log in to vote
0
Answered by 9 years ago

All GUIs are locally run. This means that the code to display the GUI is executed on the players computer and that GUIs must be put in local scripts. Because of this, you should reference the player owner of the script instead.

0
Dewn, I kinda already answered the question... He asked me to help him on another question. EzraNehemiah_TF2 3552 — 9y
0
Is there a way to do this from a noraml script instead of a local script? emite1000 335 — 9y
Ad
Log in to vote
0
Answered by
dyler3 1510 Moderation Voter
9 years ago

Ok, here's a simple solution. I think DewnOracle already kind of answered this, but I'm not sure if you understood. Make sure that the following code is inside a LocalScript, that's in the TextButton.

TextButton.MouseButton1Click:connect(function()
    player=game.Players.LocalPlayer --This gets the player that the gui is inside of, and sets the variable to him/her.
local scroll = player.PlayerGui.Chat
0
Is there a way to do this from a noraml script instead of a local script? emite1000 335 — 9y

Answer this question