This is in a normal script
Script:-
1 | local textButton = script.Parent |
2 |
3 | textButton.MouseButton 1 Down:connect( function (player) |
4 | print ( "I got clicked by " ..player.Name) |
5 | end ) |
Error:-
1 | Workspace.Part.SurfaceGui.Frame.TextButton.Script: 4 : attempt to index local 'player' (a number value) |
2 | Stack Begin |
3 | Script 'Workspace.Part.SurfaceGui.Frame.TextButton.Script' , Line 4 |
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):
1 | script.Parent.Adornee = Workspace.Part; |
2 | local plr = game.Players.LocalPlayer; |
3 | script.Parent.Frame.TextButton.MouseButton 1 Down:connect( function () |
4 | print 'I got clicked by ' ..plr.Name; |
5 | 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.
1 | local textButton = script.Parent |
2 | local player = game.Players.LocalPlayer |
3 |
4 | textButton.MouseButton 1 Down:connect( function () |
5 | print ( "I got clicked by " ..player.Name) |
6 | end ) |