Developer product giving 2x the reward (it is purchased 2 times instead of one)

I want to give money when the player purchases a developer product but, when a player buys a developer product, he gets 2x the amount.
For example he buys 500 money, the code to give him 500 money runs twice and he gets 1000 money.

MarkerplaceService.ProcessReceipt = function(reciept)
	local plr = game.Players:GetPlayerByUserId(reciept.PlayerId)
	
	if not plr then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	local money = plr.leaderstats.Money

	local ProductId = reciept.ProductId
	
	if ProductId == 1878979396 then
		money.Value += 20
	elseif ProductId == 1878979752 then
		money.Value += 40
	elseif ProductId == 1878979749 then
		money.Value += 60
	elseif ProductId == 1878979751 then
		money.Value += 100
	elseif ProductId == 1878979753 then
		money.Value += 150
	elseif ProductId == 1878979755 then
		money.Value += 500
	end
	
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

I see this doesn’t always happen. Only sometimes. There is no other script in my game that handles developer products.

For my developer products I’ve been using this script and it seems to be working:

local MarketplaceService = game:GetService("MarketplaceService")

local Products = {
	[000000000]= function(receipt,player)
		-- Put code here
	end;
}

function MarketplaceService.ProcessReceipt(receiptinfo)
	local playerProductKey = receiptinfo.PlayerId..":"..receiptinfo.PurchaseId
	local plr = game:GetService("Players"):GetPlayerByUserId(receiptinfo.PlayerId)

	local handler
	for ProductId,func in pairs(Products) do
		if ProductId == receiptinfo.ProductId then
			handler = func break
		end
	end

	local suc = pcall(handler,receiptinfo,plr)
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

Hello!

It looks like the logic in this function is fine, it shouldn’t be returning twice, which likely means its being fired twice.

Would you be able to provide the instance where the function is being called?

Thanks!

the function is called after the player purchases the developer product.
“MarketplaceService.ProcessReciept” here.

Here is also the code that prompts the purchase if it may help:

for i, Product in BrainrotFrame:GetChildren() do
	if not Product:IsA("Frame") then continue end
	Product.Buy.Activated:Connect(function()
		local ProductId

		local Amount = Product.Amount.Text
		local numberString = Amount:gsub("%D", "")
		local AmountNumber = tonumber(numberString)
		
		if AmountNumber == 20 then
			ProductId = 1878979396
		elseif AmountNumber == 40 then
			ProductId = 1878979752
		elseif AmountNumber == 60 then
			ProductId = 1878979749
		elseif AmountNumber == 100 then
			ProductId = 1878979751
		elseif AmountNumber == 150 then
			ProductId = 1878979753
		else
			ProductId = 1878979755
		end
		MarkerplaceService:PromptProductPurchase(plr, ProductId)
	end)
end
1 Like

I am wondering if the button you are using is firing once on down press and once when you let go of it? Everything looks fine here and that is the only thing I could think would be causing to fire twice.

Thank you for the code, super helpful!

every time i click, it fires only once. and the prompt also only shows once. i see that it only happens when im in a server with another player and not always. only sometimes

maybe i should add like a 0.5 second cooldown on buying gamepasses? like a player gets a value inside of it when he buys something and it gets deleted. if the player has the value then he wont get any rewards

that sounds like a really good approach to prevent the doubling issue youre having. I am genuinely not sure what would be causing this, but having a player ID system should fix it. With what youre doing here, make sure you are only calling this function on the condition that the for statement is indexing your player specfiically.

i just tried that and looks like this works very well

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.