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