Why does this UpdateAsync not work and doesn't even print out any error?
I've be trying to get get this chunk of code to save the players coins when they leave; I don't mean to use SetAsync either. The first two print (the CoinValue and the string inside the pcall) prints, but the prints at the bottom doesn't print (the if statements nor the print under the end). Needless to say, the CoinValue isn't being updated. And I've also checked that newValue isn't nil from the print(CoinValue) and it is a number.
01 | Players.PlayerRemoving:Connect( function (player) |
02 | local key = tostring (player.UserId) |
03 | local CoinValue = PlayerCoins:FindFirstChild(key).Value |
04 | local CoinStore = DataStoreService:GetDataStore( "CoinStore" ) |
07 | local success, Result = pcall ( function () |
08 | print ( "running function" ) |
09 | CoinStore:UpdateAsync(key, function (oldVal) |
10 | local newVal = CoinValue |
26 | print ( "nope it failed" ) |