Hi, I have a problem, I’m currently making a data store for saving data. I’m testing to see if it works. This data store utilizes UpdateAsync(). I have read various articles on UpdateAsync(), none have really showed me how exactly to use it to save data or to increment it.
Here’s my code, should be pretty easy to understand:
local DataStoreServ = game:GetService("DataStoreService")
local Ds = DataStoreServ:GetDataStore("DataForAllLeaderstats")
local function PlayerAdded(Player)
local Key = "Player-"..Player.UserId
local Folder = Instance.new('Folder')
Folder.Parent = Player
Folder.Name = "leaderstats"
local Coins = Instance.new("IntValue")
Coins.Name = "Coins"
Coins.Value = 0
Coins.Parent = Folder
local Exp = Instance.new("IntValue")
Exp.Name = "Exp"
Exp.Parent = Folder
Exp.Value = 0
local success, err = pcall(function()
Data = Ds:GetAsync(Key)
end)
if Data then
print("Found Data")
print(Data)
else
for i,v in pairs(Folder:GetChildren()) do
v.Value = 0
end
end
end
local function OnPlayerLeft(Player)
local Key = "Player-"..Player.UserId
local success, err = pcall(function()
Ds:UpdateAsync(Key, function(OldValue)
-- I don't know what exactly to put here.
end)
end)
end
game.Players.PlayerAdded:Connect(PlayerAdded)
game.Players.PlayerRemoving:Connect(OnPlayerLeft)
What exactly would I put in the UpdateAsync() function for it to save the data?
Any articles, posts or pieces of code, would be greatly appreciated!