I am wondering if there is a way to move saves from one data store key over to another, but in the same data store. I have a data store in my game where I save the players data. I realized that the key I am using is just they’re UserId and I learned that you should put UserId-datastored. In my game I am storing the amount of “clicks” a player have and right now the key is just userid, and I want to change it to userid-clicks so that the “clicks” can be stored on the same DataStore as other values that I might want to save. I suppose that when adding other things on the data store I can properly use the keys and the only improper key would be the “clicks.” But, I thought I would see if anyone knows a solution.
I thought about having a script save the old data to a new key but realized that then I would constantly be doing that and it would be a hassle.
It is not a huge deal but if someone knows a easy way to do this please let me know. I am not very good at Data Stores…
Where did you learn to do that? You’re not limited to a single DataStore per game. In fact, several DataStores and Scopes are often used.
EDIT: Even the Wiki page for GetDataStore uses "Player_" .. userId for scope, and then has different DataStores within each scope (for each player) called “Stats” and “Resources”.
userId = UserId of the Player
datastore = Your DataStore
local data = datastore:GetAsync(userId.."-clicks")
if data == nil then
local legacyData = datastore:GetAsync(userId)
if legacyData ~= nil then
data = legacyData
end
end
This checks if players have the new data. If not (new player or player before the data conversion), it checks if they got the data in the old key. If so, it sets their data the same as their previous data
Of course, as previous replies state, you don’t need to change the key.
Ok, I am aware that it is pointless and I can use multiple data stores. I was watching an older tutorial on data stores and this method of using keys for different stats. I did not know if this was a good method or not. Also, thanks @RafDev for pointing that out about the wiki. I did not know if there was a good way of doing it or if it was necessary I just thought I would ask.