I tried to increase a value in a player's leaderstats by 1,000 every time they purchase a developer product, but it keeps multiplying 1,000 by the number of times the product was purchased. (Example: First time buying I would get 1,000, but next time I would get 2,000 instead of 1,000) I expected the script to add 1,000 every time. Here is my ProcessReceipt script (located in ServerScriptService):
local MarketplaceService = game:GetService("MarketplaceService") local ReplicatedStorage = game:GetService("ReplicatedStorage") local DataStoreService = game:GetService("DataStoreService") local Players = game:GetService("Players") local mainDataStore = DataStoreService:GetDataStore("MainData") local function processReceipt(receiptInfo) local player = Players:GetPlayerByUserId(receiptInfo.PlayerId) if not player then return Enum.ProductPurchaseDecision.NotProcessedYet end if receiptInfo.ProductId == 1018802173 then player.leaderstats.Coins.Value += 1000 mainDataStore:SetAsync("Coins_" .. receiptInfo.PlayerId, player.leaderstats.Coins.Value) ReplicatedStorage.SendClientMessage:FireClient(player, "The game has been saved!") end return Enum.ProductPurchaseDecision.PurchaseGranted end MarketplaceService.ProcessReceipt = processReceipt
There are no errors on the server or the client, and I tested on Roblox Studio instead of a live Roblox server so I could use test purchases.
You should track how many times they buy it like example(If they bought 1000 for the first time then it would add 1 to the bought count then make it so next time they buy the script does
if player.ProductBuys.Value >= 2 then player.leaderstats.Coins.Value += 1000 * ProductBuys.Value else player.leaderstats.Coins.Value += 1000 els
Hope this helps I hope I explained the best I can