Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do transfer data from the old data store to the new one?

Asked by 10 years ago

Ok so in my place, I use the old data store to save Kills, Deaths, XP, etc... But sometimes I lose all my data for some reason, and I don't even know why, so I want to use the new data store. But the thing is, I'm not very familiar with the new data store, and the wiki website doesn't explain it very well to me, so I was wondering if someone else could explain it for me. For example, how would I transfer this:

--Somewhere in one script...
Player:SaveNumber("KillCount",Kills)
Player:SaveNumber("DeathCount",Deaths)
Player:SaveNumber("XP",PlayerXP)

--Somewhere in another script...
local Kills = Player:LoadNumber("KillCount")
local Deaths = Player:LoadNumber("DeathCount")
local XP = Player:LoadNumber("XP")

to the new data store?

1 answer

Log in to vote
1
Answered by 10 years ago

Well first you will need to set the datastore:

local datastore = game:GetService("DataStoreService"):GetDataStore("Game");

The way to set variables is similar to data persistence. There are three ways to change, set, or modify a "key" which is essentially the value given in the DataStore to get the variable you set to it. Examples of these ways are:

datastore:SetAsync("KeyName", value/variable);
datastore:UpdateAsync("KeyName", function() return value/variable end);
datastore:IncrementAsync("KeyName", incrementamount);

I believe UpdateAsync to be the most reliable out of all of these so I will use that:

local playerData = {Kills, Deaths, XP};
datastore:UpdateAsync(PlayerName, function() return playerData end} --You will need to get the player's name somehow for this.

To get the information from the datastore you use GetAsync. For example:

datastore:GetAsync(PlayerName);

That will return the table we assigned earlier.

0
Thanks! It really helped TurboFusion 1821 — 10y
Ad

Answer this question