Can two players in a game have the same name or is it not possible? I use Player.Name for my tables

I am wondering if there will be any chances of conflicts? Or is it safe???

Not sure if it is possible for two players to have the same name. I believe that ROBLOX has some kind of alias name system now??? Does anybody have any experience with this or know?

1 Like

2 players can have the same display name, not username. Player.Name will always return the player username, not display name.

For storing anything in a table, i dont recommend using the player name. Use the PlayerId instead.

2 Likes

If I just use the PlayerId wouldn’t I have to reference the Player then the PlayerId in order to get the value?

What about using Player and PlayerId at the same time??? Wouldn’t that be better?

game.Players[Player.Name]
Then check for PlayerId for a match??? Is that what you mean?

1 Like

Well yes, but im sure there is a work around to this.
Posibly a separate table that stores the the PlayerId relative to the player name.
Here is an example

local P_ID_t = { 
[Player.Name] = Player.UserId 
}

Then when you want to access the player, simply use the table

local tableofplayers = {
[1234567890] = "SuperEpicCoolDude";
}

print(tableofplayers[P_ID_t[Player.Name]]) -- Prints SuperEpicCoolDude

Its a weird way around it but if it helps then it works!
I hope this helps! :slight_smile:

1 Like

Roblox has built-in functions to reference the player with different types of data.

Remember, there’s player.Name, player.DisplayName and player.UserId, all properties of the player instance. DisplayName will not be used for referencing and differentiating players. Name is fine, but players can change names, so it’s better to use the permanent UserId for data storing, teleporting and so forth.

Let’s say you want to reference me, and I can be found among players in the Players service.

  • You know my name:
local me = Players:FindFirstChild("my_username")
if me then ... end

:FindFirstChild() is for precauting in case I am not there to be found :slight_smile:

  • You know my username:
local me = Players:GetPlayerByUserId(my_id_here)
if me then ... end

Then there are also async versions for players that are not in game.

GetNameFromUserIdAsync(name_here) and GetUserIdFromNameAsync(id_here)

Of course, you often don’t need these functions because my player instance will be passed when I join.

game:GetService("Players").PlayerAdded:Connect(function(player)
    -- when I join, that's me
end)
2 Likes

Thank you!

GetPlayerByUserId is the best method for this use case!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.