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

Devproduct handler get multiply help?

I tried to mix 2 Devproducthandler but the rewards got multiply every purchase plss help

---//DEV RECEIPT\\---
--//MAIN
MarketplaceService.ProcessReceipt = function(receiptInfo)
	--//LOCALS
	--//PART 1
	local Success, Error = pcall(function()
	local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
	local amount = Products[receiptInfo.ProductId]
		
	player.leaderstats.Donated.Value = player.leaderstats.Donated.Value + amount
	player.playerstats.Dpoints.Value = player.playerstats.Dpoints.Value + amount
	end)
	
		--//PART 2
	local plrId = receiptInfo.PlayerId
	local purchasedId = receiptInfo.ProductId
	
	for i, pass in pairs(gamepasses) do

		local passId = pass[1]
		local productId = pass[2]

		if purchasedId == productId then

			local giftUserId = playersGifted[plrId]
			if giftUserId then
				playersGifted[plrId] = nil
				
				local success, err = pcall(function()
					giftedData:SetAsync(giftUserId .. "-" .. passId, true)
				end)
				
				if success then
					return Enum.ProductPurchaseDecision.PurchaseGranted
				else
					return Enum.ProductPurchaseDecision.NotProcessedYet
				end
			else
				return Enum.ProductPurchaseDecision.NotProcessedYet
			end
		end
	end
end

2 answers

The problem here is your awarding the player twice. The first time you give the player their purchase, you should use an if statement for it.

1 comment

0

Can you do it for me? I'm still new and not familiar with other things such as pcall

I Rewrite the script and it shows no error. however it doesn't reward the player

MarketplaceService.ProcessReceipt = function(receiptInfo)
	--//LOCALS
	local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
	local amount = Products[receiptInfo.ProductId]
	
	local plrId = receiptInfo.PlayerId
	local purchasedId = receiptInfo.ProductId

	for i, pass in pairs(gamepasses) do

		local passId = pass[1]
		local productId = pass[2]
		local giftUserId = playersGifted[plrId]		
		
	local function ForSelf()
		local Success, Error = pcall(function()
		local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
		local amount = Products[receiptInfo.ProductId]

		player.leaderstats.Donated.Value += amount or 0
		player.playerstats.Dpoints.Value += amount or 0
		end)
	
	if Success then 
		return Enum.ProductPurchaseDecision.PurchaseGranted	
	else 
		warn(Error)
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end 
end
				
	local function ForSomeone()
		if giftUserId then
			playersGifted[plrId] = nil

		local success, err = pcall(function()
			giftedData:SetAsync(giftUserId .. "-" .. passId, true)
		end)
				
				if success then	
					return Enum.ProductPurchaseDecision.PurchaseGranted
				else
					return Enum.ProductPurchaseDecision.NotProcessedYet
				end	
			end
			
		
			
		
		if purchasedId == productId then
			ForSomeone()
		else
				ForSelf()
			end
		end
	end
end

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