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.
local plr = game:GetService("Players").LocalPlayer local name = plr.Name 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:
local player = game.Players:GetService("Players").LocalPlayer local name = player.Name print(name)
Or I would just do this:
LocName = local name 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
local plr = game:GetService("Players").LocalPlayer -- or you can do game.Players.LocalPlayer local name = plr.Name print(name)
Use PlayerAdded