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

Why does the purchased value doubles every time you buy it? >:((((

I have a developer product integrated into a GUI and it works just fine. It gives you 100 gold on purchase. However, when you buy it a second time it gives you 200! Can you smarter guys help me out?

 local MarketplaceService = game:GetService('MarketplaceService')
local devproductid = 44193926

MarketplaceService.ProcessReceipt=function(receiptInfo)
 for i, player in pairs(game.Players:GetChildren())do
  if player.userId == receiptInfo.PlayerId then
   if receiptInfo.ProductId == devproductid then
    
   
    player.Wealth.Gold.Value = player.Wealth.Gold.Value + 100
    end
   end
  
   end
     return Enum.ProductPurchaseDecision.PurchasedGranted 
end

1 answer

when I looked, my first instinct was line 10, it might be adding 200 instead of 100 due to the script needing a debounce for the event processReceipt, as the event may be being fired more than once. Try something like:

local MarketplaceService = game:GetService('MarketplaceService');
local devproductid 		= 44193926;
local debounce		= false;

MarketplaceService.ProcessReceipt=function(receiptInfo)
if debounce == false then
	debounce = true;
 	for i, player in pairs(game.Players:GetChildren())do
	  if player.userId == receiptInfo.PlayerId then
   			if receiptInfo.ProductId == devproductid then


    			player.Wealth.Gold.Value = player.Wealth.Gold.Value + 100
   		 end
   		end

   	end
	debounce = false;
     return Enum.ProductPurchaseDecision.PurchasedGranted 
end


3 comments

0

thanks bro! I'll try it.

0

I've run into another problem that wasn't an issue before. return Enum.ProductPurchaseDecision.PurchasedGranted pops up in my outfit whenever I attempt to purchase. Any thoughts on that?

0

well, one thing I have to say is that I forgot an extra end after "debounce = false" in like 18 to close that if. Also, you are returning Enum.ProductPurchaseDecision.PurchaseGranted, perhaps it is in the wrong code block?

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