DataStore and Player.UserID - Questions about impact on the uniqueness of the key

Hello Girls and Guys,

I see many examples using Player.UserId as a key but when I try it, it is changed into real number and rounded up and doesn’t match. What do you do? Convert it into strings? and back to a number to compare it? Add some string prefix like player_111111?

Thanks.

Stay Creative

Ansa

The player.UserId should always be the same, whether the player has changed their username or not. It will never change. You should always save keys with the players UserId since that will always remain the same, so if they do change the username they will still have the same data.

It’s just personal preference, you can do it either way but just for the gist of it, we do something called “concatinating” the value & string:

local PlayerKey = "Player_"..Player.UserId

We just add 2 dots to concatinate (Idk words) between the 2 so that they’re separate from each other, yet we should we get output of the “Player_” then the User ID of the Player afterwards (Or Player_8274928)

Hi,

I was wondering once you have concantenate with some prefix, what is the function to remove it when you need only the userid.

Thanks.

You could simply just do

local PlayerKey = Player.UserId

With no concatination