i’m using datastore2 to save my game’s data.
i cannot seem to figure out how to individually update one value in a table
local GameData = DataStore2("GameDataTesting1", Player)
GameData:GetTable({
["Banned"] = false,
["BannedTime"] = os.time(),
["Bux"] = 5000,
["FirstJoined"] = os.time(),
["Inventory"] = {}
})
local function UpdateValues(UpdatedValue)
-- ???
end
usually with just one value in your datastore you are easily able to update it like this:
local InventoryDataStore = DataStore2("Inventory", Player)
local function UpdateInventory(Value)
Inventory.Value = HttpService:JSONEncode(InventoryDataStore:Get(Value))
end
InventoryDataStore:OnUpdate(UpdateInventory)
When I first started out I was obsessed with making Datastore2 modules here is some examples of functions i hope you find useful
Example
function PlayerStats_DataStore:AddToStat(Player,Name_Of_Stat,Amount)
local Stats = DataStore2("Change this to what ever you want", Player)
local PlayerStatistics = Stats:GetTable(PlayerStatistics_EXAMPLE)
Stats:Update(function(PlayerStatistics)
PlayerStatistics[Name_Of_Stat] = PlayerStatistics[Name_Of_Stat] + Amount
return PlayerStatistics
end)
print(Name_Of_Stat .." : "..PlayerStatistics[Name_Of_Stat].. 'Added to '..Player.Name)
end
function PlayerStats_DataStore:SetStat(Player,Name_Of_Stat,Value)
local Stats = DataStore2("Change this to what ever you want", Player)
local PlayerStatistics = Stats:GetTable(PlayerStatistics_EXAMPLE)
Stats:Update(function(PlayerStatistics)
PlayerStatistics[Name_Of_Stat] = Value
return PlayerStatistics
end)
PlayerStats_DataStore:SaveStats(Player)
end
You can use SetTable(table), You aren’t setting any data into the datastore, So it has nothing to load, Set() is for regular values like string and numbers and SetTable() is for tables
I recommend using SetTable() then loading the game, Also it is recommended to handle data for when player joins and leaves