Hello,
In my game I use the following code:
function UpdateCoins(Player, Delta, purchased)
purchased = purchased or false
local CoinsDB = DataStore2(CoinsKey, Player)
local CoinsBefore = CoinsDB:Get(0)
local ActualDelta = Delta
if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, 9217590) and purchased == false and Delta > 0 then
ActualDelta *= 2
end
ActualDelta = math.ceil(ActualDelta)
CoinsDB:Increment(ActualDelta,0)
local Coins = CoinsDB:Get(0)
if Coins < 0 then
local ErrorTable = {
["PlayerName"] = Player.Name;
["CoinsBefore"] = CoinsBefore;
["Delta"] = Delta;
["ActualDelta"] = ActualDelta;
["CalculatedDelta"] = Coins-CoinsBefore;
["Coins"] = Coins;
["Purchased"] = purchased;
}
local ErrorString = "Coins got <0 for "..Player.Name..". "..CoinsBefore..","..Delta..","..ActualDelta..","..Coins..","..tostring(purchased)
warn(ErrorString)
AnalyticsService:FireLogEvent(Player,Enum.AnalyticsLogLevel.Error, "CoinsGotBelow0", {}, ErrorTable)
end
SetCoins:FireClient(Player,Coins, ActualDelta)
end
Before I run this function, it always checks if the coins of the player are > Delta if Delta > 0. However, the coins still get set up, and the values in the ErrorTable are sometimes:
Does anyone see how the CalculatedDelta is not equal to the ActualDelta? I don’t have any clue, but it really affects my game. Thank you in advance.