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

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

Asked by
Lacin1a 12
4 years ago
Edited 4 years ago

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

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. shotpaper7 -5 — 3y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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)
Ad

Answer this question