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

How can I add additional values to an existing datastore?

Asked by 6 years ago

So, I have a table with the default player data I need to load/save, like below.

local DefaultStats = {
    Stats = {
        Points = 0,
        Kills = 0,
        Deaths = 0,
    },
}

And I'm retrieving the DataStore like this.

local PlayerData = game:GetService("DataStoreService"):GetDataStore("TestData1")

Say I add another value to save, such as "Coins = 0,", then join the game, that value does not load since it wasn't saved on the current DataStore, TestData1 originally. If I change my DataStore name to say TestData2, I lose the previous data obviously, but the new value is loaded.

I'll need to be adding new values into the DataStore as time progresses, and I can't be resetting all the player data each time.

Is this an issue with how I'm saving/loading data, or is there something I'm missing with DataStores?

1 answer

Log in to vote
0
Answered by
Aethys 0 Donator
6 years ago

You can use SetAsync to update values.

local PlayerData = game:GetService("DataStoreService"):GetDataStore("TestData1")

PlayerData:SetAsync("DataName","DataValue")

The DataValue can be set with tables or dictionaries as well.

0
In order to set new data, you can use GetAsync to see if it's nil, then set it to a Default value if it is. Aethys 0 — 6y
0
Key? Is the key going to be the scope? Wheres da key? hiimgoodpack 2009 — 6y
Ad

Answer this question