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

Developer Product is not adding 1 to the Value?

Asked by
RoyMer 301 Moderation Voter
9 years ago

These scripts are supposed to add 1 to the Value of Stage when one buys the developer product but so far it is loading to purchase but** nothing is happening after you pay**.

I have 2 scripts, this one is placed inside the player:

01local MarketplaceService = game:GetService("MarketplaceService")
02local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
03local player = game.Players.LocalPlayer
04local stage = player.leaderstats:findFirstChild("Stage")
05CASHID = 24397415 -- Put the Developer Product ID here
06 
07MarketplaceService.ProcessReceipt = function(receiptInfo)
08    local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_product_" .. receiptInfo.ProductId
09    local numberBought = ds:IncrementAsync(playerProductKey, 1)
10    for i,v in pairs (game.Players:GetChildren()) do
11        if v.userId == receiptInfo.PlayerId then
12            if receiptInfo.ProductId == CASHID then
13 
14if stage.Value < 25 then
15    stage.Value = stage.Value + 1
View all 24 lines...

This one is placed in the button of the GUI

1local productId = 24397415
2local player = game.Players.LocalPlayer
3 
4script.Parent.MouseButton1Click:connect(function()
5    game:GetService("MarketplaceService"):PromptProductPurchase(player, productId)
6end)   
0
I'm not sure of it yet, but it seems that instead of creating this stage variable, rather use the v variable which stand for the player that bought the product, I'm not 100% sure but if you look at the tutorial on the roblox wiki (http://wiki.roblox.com/index.php/Developer_product) it references the player's leaderstats by using the for loop, otherwise good luck, someone will figure it out :P dragonkeeper467 453 — 9y

1 answer

Log in to vote
1
Answered by 9 years ago

The problem is that you are using a LocalScript for handling the purchase, where you should be using a normal Script.

What you need to do is put the code into a normal script, get rid of the player and stage variables and then use the player found in the for loop (reference by the variable 'v' without quotes) to increase their stage value.

Also, you need to return PurchaseGranted inside your purchase handling function, otherwise you will not receive any money from ROBLOX.

Overall, your final script should look like this:

01local MarketplaceService = game:GetService("MarketplaceService")
02local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
03 
04CASHID = 24397415 -- Put the Developer Product ID here
05 
06MarketplaceService.ProcessReceipt = function(receiptInfo)
07    local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_product_" .. receiptInfo.ProductId
08    local numberBought = ds:IncrementAsync(playerProductKey, 1)
09    for i,v in pairs(game.Players:GetPlayers()) do
10        if v.userId == receiptInfo.PlayerId then
11            if receiptInfo.ProductId == CASHID then
12                local stats = v:WaitForChild("leaderstats") --Yields the script until leaderstats becomes available.
13                local stage = stats:WaitForChild("Stage") --Same as above, but waits for the stage value in leaderstats.
14                local char = v.Character --Referencing the character.
15                if stage.Value < 25 then
View all 24 lines...

I hope my answer helped you. If it did, be sure to accept it.

Ad

Answer this question