Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How Do I Get A Player's Username In A Normal Script?

I know that getting a Player's username in a local script is easy, BUT I'm running a function that needs to be ran in a script. How would I get their name?

Current script I have:

local PlayerId = game.Players:GetPlayerByUserId() -- Trying to get their Id
local PlayerName = game.Players:GetUserIdFromNameAsync()

print(PlayerId)
print(PlayerName)

This is an example of how I would think of using it but it doesn't seem to work

1 comment

0

Hi, I have no idea how, but I would appreciate it if you could show me the script as I am testing some scripts for a big game I would like to create.

1 answer

✓ Accepted answer

You could use a PlayerAdded function which will fire every time a player joins the game. You can set an argument of the player and just get their userId & name from there. Example:

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

This discussion is preserved as it was. New answers, comments, and votes are closed.