I was wondering if anyone could help me with using UpdateAsync. I completely understand SetAsync, but recently I was told to switch over to this instead. On the Roblox Wiki I saw some code:
local pointsDataStore = game:GetService("DataStoreService"):GetDataStore("Points")
game.Players.PlayerAdded:Connect(function(player)
local playerKey = "Player_" .. player.UserId
-- Give 50 points to players each time they visit
local success, err = pcall(function()
pointsDataStore:UpdateAsync(playerKey, function(oldValue)
local newValue = oldValue or 0
newValue = newValue + 50
return newValue
end)
end)
end)
What is oldValue since it is never defined before the function and can I put multiple values into this?
I tried to find online resources for this, but no luck. If anyone would like to help or give me resources that would help I would greatly appreciate it.
ALSO I am specifically trying to save a dictionary, but with UpdateAsync and possibly explore JSONencoding.
EDIT:
Here is my code:
local DataStoreService = game:GetService("DataStoreService")
local PlayerStats = DataStoreService:GetDataStore("PlayerStats1")
local DefaultStats = {
["CurrentStats"] = {
["CityLevel"] = 0,
["CityPopulation"] = 0,
["CityVisits"] = 0,
["CoinsPerSecond"] = 0,
["Coins"] = 0,
["Cash"] = 0,
["AchievementsCompleted"] = 0,
["HasAirport"] = false,
["HasForeverDoubleEarnings"] = false,
},
["HighestStats"] = {
["HighestCityLevel"] = 0,
["HighestCityPopulation"] = 0,
["HighestCoins"] = 0,
["HighestCash"] = 0,
["HighestAchievementsCompleted"] = 0
}
}
game:GetService("Players").PlayerAdded:Connect(function(Player)
local playerKey = tostring("key-"..Player.UserId.."-devtechgames")
--what do i do ._.
end)