Hello! I’m currently switching from the normal Data Store to Profile Service but I ran into an issue. I can’t seem to transfer the data from the Data Store to the Profile Service. I saw a post about this but that doesn’t work for me.
This is what the post’s solution was:
local data = profile.Data
if not data.DidDataTransfer then
local oldData = game:GetService("DataStoreService"):GetDataStore("42TH"):GetAsync("id" .. player.UserId)
if oldData then
for i,v in oldData do
profile.Data[i] = v
end
end
data.DidDataTransfer = true
end
I had to insert “DidDataTransfer” into Profile Service’s dataTemplate. The reason this doen’t work is because in the for loop the i is a number, not the name of the value.
How can I transfer normal Data Store data into Profile Service?
I think it’s because of the for index, value thing. I think you got it wrong. Keys are like dictionairies which hold values. However, you’re accessing a datastore. A datastore is not a dictionary/array. I’m pretty sure when you make a new datastore using profilestore you create an actual datastore because profileservice is under the same framework. So just get the name of the profilestore name and do this.
local oldData = game:GetService("DataStoreService"):GetDataStore("42TH")
local newData = game:GetService("DataStoreService"):GetDataStore("NewData") -- Replace newdata with the name of your profilestore
-- Now this is how you can trasnfer all keys with their values.
local Pages = oldData:ListKeysAsync()
local Page = Pages:GetCurrentPage()
for Value, Key in Page do
pcall(function()
local value = datastore:GetAsync(Key.KeyName)
newData:SetAsync(Key.KeyName, value)
end)
end
Yes I just double checked and both the Data Store name and the Profile Service name are correct. How about changing the dataTemplate values in Profile Service to the Data Store values? I think that would work but the dataTemplate values are indexed with names like: XP, Level etc. Is it possible to get the name of the value stored in the normal Data Store?
Well I used to use profileservice alot when I was newer to scripting and my knowledge of datastoreservice was weaker. So I switched to profileservice which saved the headache of having to save data. However, now that I’ve been scripting for around 6-7 months I went back and used the documentation’s datastore tutorial I understand it way better and use datastoreservice instead now. So I have less knowledge in profileservice now and kinda forgot how to use it. So I’m not sure if I can help further. But to answer your final sentence:
Not really sure what you mean by name of the value? Because values don’t really have names. If you meant like get the value from a key. You can do that using getasync but I think you know how to do that. So, not sure what your question really means. Sorry but I can’t really understand your question.
Ohh, I see. Let me elaborate on my question. Let’s say, I save a value called “XP” into a Data Store.
XP is 100. If I use :GetAsync on the Data Store it would print out 100. But in order to match the indexes in Profile Service I have to know the name of the value, not how much the value is. Is it possible to get the XP as a name out of the Data Store? Hopefully I was understandable.
I would if I know how to. I couldn’t find any information about it on the devforum. You said you have a lot of knowledge in data store. How would I accomplish it?
Ohhhhh, I think you could use table.find on profile.Data? It may not work though as table.find doesn’t support dictionaries. If that doesn’t work try using table.find on the profile object as I’m pretty sure the profile is a table if I remember correctly. You could also just use a bunch of if statements for each index to check if the value is called XP.
Oh alright, That’s a bit tricky then. I haven’t used profileservice in a long time but I’m pretty sure profile.Data is probably just a dictionairy that is saved in setasync by profileservice like this:
Data = {
-- Your keys you made in profiletemplate
Cheese = 1
Robot = "true"
}
So, what you could try to do is this just before setasync:
for Every, Key in Page do
pcall(function()
local tuple = datastore:GetAsync(Key.KeyName)
if tuple and tuple.ProfileTemplateKeyName then
NewStore:SetAsync(Key.KeyName,tuple.ProfileTemplateKeyName)
end
end)
end
If that doesn’t work. I recommend looking into behind the scenes of the profileservice module script and seeing how the function profile.Data actually works, I assume it’s something similiar to what I showed though.
You might have to also use the dot operator instead of square brackets by the way.