I thought this would be easy and made it very quickly but found that it didnt work. So , I tested it alot of times to see if there is a mistake but in the end I just couldnt find it even after I tried.
So if anyone knows whats wrong with my script please explain to me. Help would be appreciated! Thanks.
This script is to get the players name.
1 | local plr = game:GetService( "Players" ).LocalPlayer |
2 | local name = plr.Name |
3 |
4 | print (name) |
it just gives me this error and idk how to fix 17:25:22.297 - Workspace.Script:2: attempt to index nil with 'Name' 17:25:22.297 - Stack Begin 17:25:22.298 - Script 'Workspace.Script', Line 2 17:25:22.298 - Stack End
I'm going out on a limp here, and I'm going to say that you didn't define where the player's name was:
1 | local player = game.Players:GetService( "Players" ).LocalPlayer |
2 | local name = player.Name |
3 |
4 | print (name) |
Or I would just do this:
1 | LocName = local name |
2 | print (LocName) |
Also the trouble may be because "name" is already a variable.
LocalPlayer
ONLY works on LOCAL SCRIPT. Notice that local script cannot run on workspace, u will need to put it in: StarterGui ,StarterPack, or StarterPlayerScript
1 | local plr = game:GetService( "Players" ).LocalPlayer |
2 | -- or you can do game.Players.LocalPlayer |
3 | local name = plr.Name |
4 |
5 | print (name) |
Use PlayerAdded