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

Why does my dev product not work correctly?

Asked by
Xenyst 0
6 years ago
Edited 6 years ago

I am having a problem with Skip stage dev product, It skips the stage fine but after the first purchase if you buy it again it will increase by two stages instead of one. Example: You are on stage 5 and skip to 6, if you try to skip from 6 to 7 you go to 8 instead and it increases by 1 so forth, how do I prevent this?

Button 4 purchase

local productId = 106153320

script.Parent.MouseButton1Click:connect(function()
    game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, productId)
end)

ServerScriptService

local MarketplaceService = game:GetService("MarketplaceService")
local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
local productId = 106153320
MarketplaceService.ProcessReceipt = function(receiptInfo) 
    for i, player in ipairs(game.Players:GetChildren()) do
        if player.userId == receiptInfo.PlayerId then
            if receiptInfo.ProductId == productId then
                player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 1
                                player.Character.Humanoid.Health = 0
            end
        end
    end 
    local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.ProductId
    ds:IncrementAsync(playerProductKey, 0)  
    return Enum.ProductPurchaseDecision.PurchaseGranted     
end
0
Bump? Xenyst 0 — 6y
0
don't use ipairs no where would it be nil and ipairs is slower than pairs hiimgoodpack 2009 — 6y
0
Tried without, same problem.. Xenyst 0 — 6y

1 answer

Log in to vote
0
Answered by
Mineloxer 187
6 years ago

Try this:

local MarketplaceService = game:GetService("MarketplaceService")
local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
local productId = 106153320
MarketplaceService.ProcessReceipt = function(receiptInfo) 
    for i, player in ipairs(game.Players:GetChildren()) do
        if player.userId == receiptInfo.PlayerId then
            if receiptInfo.ProductId == productId then
                player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 1
                player.Character.Humanoid.Health = 0
        local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.ProductId
            ds:IncrementAsync(playerProductKey, 0)  
         return Enum.ProductPurchaseDecision.PurchaseGranted     
            end
        end
    end 

Return Enum.ProductPurchaseDescision.NotProccessedYet
end

I didn't test it, but that could be because you don't break the loop when you find the player. This way, only returns PurchaseGranted, if it was successful. Otherwise, it will return NotProccessedYet.

0
Nope, same problem still occurs :/ Xenyst 0 — 6y
0
I would probably say it has something to do with the for loop. I would suggest you look into this: http://wiki.roblox.com/index.php?title=Handling_multiple_developer_products Mineloxer 187 — 6y
Ad

Answer this question