I used a product script to sell products. It is supposed to give +1 of a stat every buy. It works, but it gives +1, then +2, then +4, then +8, and so on. Why does it do that?
Here is the script.
local MarketplaceService = game:GetService("MarketplaceService") MarketplaceService.ProcessReceipt = function(receiptInfo) local PlayerBoughtID = receiptInfo.PlayerId local PlayerBought for iPlayers, vPlayer in pairs(game.Players:GetChildren()) do if vPlayer.userId == PlayerBoughtID then PlayerBought = vPlayer end end if receiptInfo.ProductId == 12345678 then -- ID HERE PlayerBought.leaderstats.Money.Value = PlayerBought.leaderstats.Money.Value + 1 end end
I'm assuming your using a DevProduct because you want repeatable in-game purchases? The following example is similar but look at the loop. I also used ipairs as it returns the function, table and int value. This loops through players for receipt info, if the receiptinfo matches the player user.id and the product matches the devprodcutId then the leaderstats Money.Value in increased. If you're not using a DevProduct you can modify it.
local MarketplaceService = game:GetService('MarketplaceService') local devproductId = 123456789 -- The ID of the dev product. MarketplaceService.ProcessReceipt = function(receiptInfo) for i, player in ipairs(game.Players:GetChildren()) do if player.userId == receiptInfo.PlayerId then if receiptInfo.ProductId == devproductId then -- Receive money player.leaderstats.Money.Value = player.leaderstats.Money.Value + 1 end end end return Enum.ProductPurchasedDescision.PurchaseGranted end