Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Stat Product Script giving wrong amount?

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

3 comments

0

Because you're generous!

0

Is this a DevProduct purchase?

0

^ I would say it's safe to assume this, since it is seemingly bought multiple times. This appears to be a very dumbed down version of a money purchasing script.

1 answer

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.