-
What I want to achieve?
I have made a data store that saves the in-game currency of the player. And once the player purchases something from the shop it should update the currency value inside the data store. -
What is the issue?
I tried using UpdateAsync() to change the currency’s value but it’s value stays the exact same, no changes in value at all.
Here’s the script:
local cost = RS:WaitForChild("Weapons"):WaitForChild("Gun"):GetAttribute("Cost") --Cost of the item
if player.leaderstats.Cash.Value >= tonumber(cost) then --If the player's cash >= cost
local result = dataStore:UpdateAsync(player.UserId, function(OldcashValue)
local newCashValue = OldcashValue[1]
newCashValue = newCashValue - cost --this should subtract the cash's value by the cost if the player has enough
return newCashValue -- returns the value
end)