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

Why won't my player.Name thing work?

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

✓ Accepted answer

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);

1 comment

0

Great answer. Thanks!

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)

2 comments

0

Hm, diddn't work..

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.

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