local ID = game.Players.LocalPlayer.userId local value = script.Parent.Parent.Parent.USERID script.Parent.Parent.Parent.USERID.Value = ID function onClicked() script.Parent.Text = value end script.Parent.Parent.Parent.ClickDetector:connect(onClicked)
Whats wrong with it :/
ClickDetectors fire the MouseClick event which returns the Player. You can't exactly use a LocalScript, since anyone can click the button at any given moment. For the parameter for the function, you'd set the Player
variable. On your line 7, you were setting the text equal to an Object, which is impossible. You need to add .Value
. Here is your script fixed up, with more organization (Normal script):
script.Parent.Parent.Parent.ClickDetector.MouseClick:connect(function(Player) script.Parent.Text = Player.userId end)
The use of those variables wasn't needed, unless you were using them in another script as well. If that's the case, then:
script.Parent.Parent.Parent.ClickDetector.MouseClick:connect(function(Player) script.Parent.Parent.Parent.USERID.Value = Player.userId script.Parent.Text = Player.userId end)
Think of it this way. Storing a variable is like taking a picture of someone. After the picture is taken, the person can move around all he wants, but he remains still in the picture. If you store how fast a part is moving at a given moment, then you have that one number that won't change, but the part's speed will. So, in this example, switch lines 2 and 4 around.
local ID = game.Players.LocalPlayer.userId script.Parent.Parent.Parent.USERID.Value = ID local value = script.Parent.Parent.Parent.USERID.Value --Gotta change USERID to USERID.Value function onClicked() script.Parent.Text = value end script.Parent.Parent.Parent.ClickDetector:connect(onClicked)