Hello, for whatever reason, no data saves when the player leaves. Any ideas? I am new to datastores and using UpdateAsync().
local DataStoreService = game:GetService(“DataStoreService”)
local CashSave = DataStoreService:GetDataStore(“Cash”)
local WinsSave = DataStoreService:GetDataStore(“Wins”)
game.Players.PlayerAdded:Connect(function(player)
local Folder = Instance.new(“Folder”)
Folder.Name = “leaderstats”
Folder.Parent = player
local CashValue = Instance.new("NumberValue")
CashValue.Name = "Cash"
CashValue.Parent = Folder
CashValue.Value = CashSave:GetAsync(player.UserId)
local WinsValue = Instance.new("NumberValue")
WinsValue.Name = "Wins"
WinsValue.Parent = Folder
WinsValue.Value = WinsSave:GetAsync(player.UserId)
end)
game.Players.PlayerRemoving:Connect(function(player)
CashSave:UpdateAsync(player.UserId , function(test)
test = player.leaderstats.Cash.Value
end)
WinsSave:UpdateAsync(player.UserId , function(test)
test = player.leaderstats.Cash.Value
end)
end)