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