I made a huge mistake on my game [Datastore]

So I made a game and made it public around 18 days ago.
In that game , I use a simple Datastore which saves what needed to be save.
the problem is , my ‘key’ on the save is based on Player Name and not User ID. For example ,

I never think of “what if a player changed their name?” until today , somebody personally contact me about this. They wanted me to transfer their ‘old name save’ to their ‘new name save’ which I have no idea how to do.

Have any of you guys have any idea how I can solve this?
I’m also using this https://www.roblox.com/library/701506235/DataStore-Editor best plugin for Datastore editing/visualization I’ve ever found.

I regret not using the Player’s User ID at first . Now that the game have many and many concurrent player which is impossible for me to change the Datastore keys without making the player angry for data-reset.

If there is no other ways , I hope none of you guys ever do my mistake.

Welp you’re screwed. But what you can do for now is when a player joins get their current data and save that to the key with their ID.

local KEY_PREFIX = "Slot1_"

    local old_key = KEY_PREFIX .. player.Name
    local new_key = KEY_PREFIX .. player.UserId

    local old_data = data_store:GetAsync(old_key)

    if old_data ~= nil then
        data_store:SetAsync(new_key, old_data)

That is just very rough code, you should still do good examples like wrapping these requests in pcall but that is just an example.

Might wanna keep that for about 2 weeks-1 month max for recovery time.

1 Like

  local name = player.Name;
  local id = player.UserId;

  local nameData = 'Slot1_' .. name;
  local idData = 'Slot1_' .. id;

  --load the data store using <idData> as the key. If it is empty, load the data store using <nameData>.
  --this will get a users data if they haven't changed their name

  --When it comes to saving the players data, save it using <idData> as the key.

  --If you have a user contact you about losing their data, ask for their old username and move over their data to the <idData> key using the data store plugin you've got.

1 Like

Thanks , I completely understand both of replies I got :smile: