Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I add additional values to an existing datastore?

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

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.

2 comments

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.

0

Key? Is the key going to be the scope? Wheres da key?

This discussion is preserved as it was. New answers, comments, and votes are closed.