Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Stat Product Script giving wrong amount?

Asked by
OhManXDXD 445 Moderation Voter
6 years ago

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
0
Because you're generous! DaggerOf_Fly -24 — 6y
0
Is this a DevProduct purchase? ABK2017 406 — 6y
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. SummerEquinox 643 — 6y

1 answer

Log in to vote
0
Answered by
ABK2017 406 Moderation Voter
6 years ago

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
Ad

Answer this question