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
8 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:

local MarketplaceService = game:GetService("MarketplaceService")
local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
local player = game.Players.LocalPlayer
local stage = player.leaderstats:findFirstChild("Stage") 
CASHID = 24397415 -- Put the Developer Product ID here

MarketplaceService.ProcessReceipt = function(receiptInfo)
    local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_product_" .. receiptInfo.ProductId
    local numberBought = ds:IncrementAsync(playerProductKey, 1)
    for i,v in pairs (game.Players:GetChildren()) do
        if v.userId == receiptInfo.PlayerId then
            if receiptInfo.ProductId == CASHID then

if stage.Value < 25 then 
    stage.Value = stage.Value + 1
    wait(1)
    player.Character.Head:Remove()
end
                    end
                end
            end
        end

    return Enum.ProductPurchaseDecision.PurchaseGranted 

This one is placed in the button of the GUI

local productId = 24397415 
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect(function()
    game:GetService("MarketplaceService"):PromptProductPurchase(player, productId)
end)    
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 — 8y

1 answer

Log in to vote
1
Answered by 8 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:

local MarketplaceService = game:GetService("MarketplaceService")
local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")

CASHID = 24397415 -- Put the Developer Product ID here

MarketplaceService.ProcessReceipt = function(receiptInfo)
    local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_product_" .. receiptInfo.ProductId
    local numberBought = ds:IncrementAsync(playerProductKey, 1)
    for i,v in pairs(game.Players:GetPlayers()) do
        if v.userId == receiptInfo.PlayerId then
            if receiptInfo.ProductId == CASHID then
                local stats = v:WaitForChild("leaderstats") --Yields the script until leaderstats becomes available.
                local stage = stats:WaitForChild("Stage") --Same as above, but waits for the stage value in leaderstats.
                local char = v.Character --Referencing the character.
                if stage.Value < 25 then
                    stage.Value = stage.Value + 1
                    --No need for the wait. The script will wait if the character's humanoid doesn't exist yet.
                    char:WaitForChild("Humanoid").Health = 0 --Waits for the humanoid then kills it by setting it's health to 0.
                end
            end
        end
    end
    return Enum.ProductPurchaseDecision.PurchaseGranted --You need to return PurchaseGranted in your function, otherwise you will not recieve any money from a transaction.
end

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

Ad

Answer this question