How can I get the player name by script?

How can I get a player name using a script? If you know please reply below and I will mark it as a Solution thank you!

15 Likes

As in a local script? If you’re using a local script, the Players service has a property called LocalPlayer that gives the player instance on that client, so all you would need to do to get the player’s name is game:GetService(“Players”).LocalPlayer.Name.

8 Likes
local player = -- ... the player, e.g. game.Players.LocalPlayer or game.Players.nicemike40
print(player.Name)

Something tells me that that’s not exactly what you’re asking, though.

3 Likes

idk tbh cause im doing a folder creator script that renames the folder with the player name i already did that and this is working im working on moving whatever the player’s build into the player’s personal folder thats why i asked how i can know what is the player’s name

3 Likes
--Script
game.Players.PlayerAdded:Connect(function(thisPlayer)
    local playerName = thisPlayer.Name
    print(playerName)
end)
6 Likes

I made a new post explaining my problem if you could check it out

3 Likes

LocalScript:

local Player = game:GetService("Players").LocalPlayer

Player.Name = Name

ServerScript:

game.Players.PlayerAdded:Connect(function(player)

player.Name = Name
9 Likes

You don’t need to define “local playerName” as a local, as this is being used in a ServerScript, otherwise define local in a localscript.

3 Likes

I know this, I just want to declare this to show the actual instance for Names. so its easy to understand.

2 Likes

Make sure to mark the solution if someone already answered your question,

Basically you can get the player through game.Players.Playername
You can also get the player through connections for example:

game.Players.PlayerAdded:Connect(function(Player)
print(Player.Name)
end)

There’s lots of different connections and functions you can use to get the player for example: Players:GetPlayersFromCharacter.

25 Likes

How can i get the name if i dont want to make it a function cause the script im using isn’t executed when the player join the game

6 Likes

It’s really hard to answer this question if there’s no context or script shown here, we don’t know what you’re doing or how you’re trying to get the player’s name.

Please let us know more.

2 Likes

I have made a recent post explaining my problem its on my Profile - Activity and then u can find my recent other post

2 Likes

if you’re asking how to get a localplayer on server you can do

local plr = game:GetService("Players"):GetPlayerFromCharacter(script.Parent)
print(plr)
5 Likes

If your script is in StarterGui then you can write local Player = script.Parent.Parent, or you can use RemoteFunction using additional localscript which will return player

1 Like