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

Why won't my player.Name thing work?

Asked by 10 years ago

This is in a normal script

Script:-

local textButton = script.Parent

textButton.MouseButton1Down:connect(function(player)
    print ("I got clicked by " ..player.Name)
end)

Error:-

Workspace.Part.SurfaceGui.Frame.TextButton.Script:4: attempt to index local 'player' (a number value)
Stack Begin
Script 'Workspace.Part.SurfaceGui.Frame.TextButton.Script', Line 4
Stack End

What I am trying to do is when the text box is clicked(which is in a surfacegui) it will print that the box was clicked by the player.

Any help please? :)

2 answers

Log in to vote
2
Answered by 10 years ago

What you're trying to do isn't correct. Before I continue, I'd suggest looking at the > Adornee < property of SurfaceGuis. First off, keep the SurfaceGui in StarterGui and put this in the GUI (localscript):

script.Parent.Adornee = Workspace.Part;
local plr = game.Players.LocalPlayer;
script.Parent.Frame.TextButton.MouseButton1Down:connect(function()
print'I got clicked by '..plr.Name;
end);
0
Great answer. Thanks! WelpNathan 307 — 10y
Ad
Log in to vote
1
Answered by 10 years ago

Your problem is that the MouseButton1Down function does not return the player.

Therefore you have to access the player's name from the LocalPlayer.

local textButton = script.Parent
local player = game.Players.LocalPlayer

textButton.MouseButton1Down:connect(function()
    print ("I got clicked by " ..player.Name)
end)

0
Hm, diddn't work.. WelpNathan 307 — 10y
0
Yeah, I didn't realize it was in a SurfaceGui. However it still should work, as long as it is in a LocalScript. Either way, someone else answered your question. SlickPwner 534 — 10y

Answer this question