Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you get the name of the localPlayer?

Asked by
6zk8 95
4 years ago
local player = game:GetService("Players")
local Lplayer = tostring(player.LocalPlayer)
print(Lplayer)

It dosen't print out the LocalPlayer's username. Help please!

0
You don't need tostring before the localPlayer; it is already a string value IAmNotTheReal_MePipe 418 — 4y

3 answers

Log in to vote
0
Answered by 4 years ago

If this is via a Local Script, you can simply do

local player = game.Players.LocalPlayer
print(player.Name)

However if this is in a server script, I'm pretty sure you cannot do this. You can only get a player by using Events I believe. eg: A PlayerAdded event, etc.

Ad
Log in to vote
0
Answered by 4 years ago
local player = game.Players.LocalPlayer
print(player.Name)
0
It doesn't work. 6zk8 95 — 4y
0
Im getting "Players.6zk8.PlayerGui.ScreenGui.TextLabel.Script:4: attempt to index nil with 'Name"' 6zk8 95 — 4y
Log in to vote
0
Answered by 4 years ago
wait(0.5)
local plr = game.Players.LocalPlayer
print(plr.Name)

Answer this question