Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does my dev product not work correctly?

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

3 comments

0

Bump?

0

don't use ipairs no where would it be nil and ipairs is slower than pairs

0

Tried without, same problem..

1 answer

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.

2 comments

0

Nope, same problem still occurs :/

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

This discussion is preserved as it was. New answers, comments, and votes are closed.