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!
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.
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.
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
--Script
game.Players.PlayerAdded:Connect(function(thisPlayer)
local playerName = thisPlayer.Name
print(playerName)
end)
I made a new post explaining my problem if you could check it out
LocalScript:
local Player = game:GetService("Players").LocalPlayer
Player.Name = Name
ServerScript:
game.Players.PlayerAdded:Connect(function(player)
player.Name = Name
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.
I know this, I just want to declare this to show the actual instance for Names. so its easy to understand.
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.
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
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.
I have made a recent post explaining my problem its on my Profile - Activity and then u can find my recent other post
if you’re asking how to get a localplayer on server you can do
local plr = game:GetService("Players"):GetPlayerFromCharacter(script.Parent)
print(plr)
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