I made a developer product system. For some reason, if the player has more than 0 Treasure, it all the products give more Treasure than they are supposed to. Here's the code.
local marketplaceService = game:GetService("MarketplaceService") local productID = 305518579 --100 Treasure local productID2 = 305551012 --500 Treasure local productID3 = 305580165 --1000 Treasure local productID4 = 305663788 --2500 Treasure local productID5 = 305667113 --5000 Treasure marketplaceService.ProcessReceipt = function(receiptInfo) for i, player in ipairs(game.Players:GetChildren()) do if player.userId == receiptInfo.PlayerId then if receiptInfo.ProductId == productID then local treasure = player.leaderstats.Treasure local totalTreasure = player.TotalTreasure treasure.Value = treasure.Value + 100 totalTreasure.Value = player.TotalTreasure.Value + 100 end if receiptInfo.ProductId == productID2 then local treasure = player.leaderstats.Treasure local totalTreasure = player.TotalTreasure treasure.Value = treasure.Value + 500 totalTreasure.Value = totalTreasure.Value + 500 end if receiptInfo.ProductId == productID3 then local treasure = player.leaderstats.Treasure local totalTreasure = player.TotalTreasure treasure.Value = treasure.Value + 1000 totalTreasure.Value = totalTreasure.Value + 1000 end if receiptInfo.ProductId == productID4 then local treasure = player.leaderstats.Treasure local totalTreasure = player.TotalTreasure treasure.Value = treasure.Value + 2500 totalTreasure.Value = totalTreasure.Value + 2500 end if receiptInfo.ProductId == productID5 then local treasure = player.leaderstats.Treasure local totalTreasure = player.TotalTreasure treasure.Value = treasure.Value + 5000 totalTreasure.Value = totalTreasure.Value + 5000 end end end end
the answer is: you used a for loop, therefore executing everything inside the loop multiple times.
for i, player in ipairs(game.Players:GetChildren()) do
Found out what I did wrong. I forgot to add the
return Enum.ProductPurchaseDecision.PurchaseGranted
at the end. I remembered that until "PurchaseGranted" is returned, ProcessReceipt() is ran every few seconds. For anyone with this problem, this may be the solution.