I've already asked the dev of the studio I'm in and we couldn't figure it out. Anyway, Every time, it prints the error (errorMsg from pcall arg). The key is the players ID (not number but string) and CoinValue is a number. I've already SetAsync it so it's a valid datastore entry.
Players.PlayerRemoving:Connect(function(player) local CoinValue = PlayerCoins:FindFirstChild(tostring(player.UserId)) print(CoinValue.Value) local CoinStore = DataStoreService:GetDataStore("CoinStore") local key = tostring(player.UserId) local success, errorMsg = pcall(function() CoinStore:UpdateAsync(key,CoinValue.Value) end) if success then print("yay") print(success) elseif errorMsg then print("nope") print(success) end end)
You have to provide a function to UpdateAsync. It will also return the old saved value if you need it.
local Players = game:GetService('Players') local DataStoreService = game:GetService('DataStoreService') local CoinStore = DataStoreService:GetDataStore("CoinStore") Players.PlayerRemoving:Connect(function(player) local key = tostring(player.UserId) local CoinValue = PlayerCoins:FindFirstChild(key).Value print(CoinValue) local success, errorMsg = pcall(function() CoinStore:UpdateAsync(key, function() return CoinValue end) end) if success then print("yay") else print("nope") print(errorMsg ) end end)