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.

01local MarketplaceService = game:GetService("MarketplaceService")
02 
03MarketplaceService.ProcessReceipt = function(receiptInfo)
04 
05    local PlayerBoughtID = receiptInfo.PlayerId
06    local PlayerBought
07    for iPlayers, vPlayer in pairs(game.Players:GetChildren()) do
08        if vPlayer.userId == PlayerBoughtID then
09            PlayerBought = vPlayer
10        end
11    end
12    if receiptInfo.ProductId == 12345678 then -- ID HERE
13        PlayerBought.leaderstats.Money.Value = PlayerBought.leaderstats.Money.Value + 1
14    end
15    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.

01local MarketplaceService = game:GetService('MarketplaceService')
02local devproductId = 123456789 -- The ID of the dev product.
03 
04MarketplaceService.ProcessReceipt = function(receiptInfo)
05    for i, player in ipairs(game.Players:GetChildren()) do
06        if player.userId == receiptInfo.PlayerId then
07            if receiptInfo.ProductId == devproductId then
08 
09                -- Receive money
10                player.leaderstats.Money.Value = player.leaderstats.Money.Value + 1
11            end
12        end
13    end
14    return Enum.ProductPurchasedDescision.PurchaseGranted
15end
Ad

Answer this question