Multiple Developer products

How to make a multiple donation system
When i tried to make donate 10 robux and 15 robux, then only 10 worked, if I bought for 15 then the event came as for 10 robux. How can I fix this?
code:

local service = game:GetService("MarketplaceService")

Service.ProcessReceipt = function(new)
Local plr = game.Players:GetPlayerByUserId(new.PlayerId)
If new.ProductId == example then
Game.ReplicatedStorage.event:FireClient(plr)
Elseif ProductId == example2 then
Game.ReplicatedStorage.Event2:FireClient(plr)
Return Enum.ProductPurchaseDecision.PurchaseGranted
end
end 

And i tried other method:Instead of elseif
I made 15 robux developer product as other script.but still not working.

local service = game:GetService("MarketplaceService")

Service.ProcessReceipt = function(new)
Local plr = game.Players:GetPlayerByUserId(new.PlayerId)
If new.ProductId == example2 then
Game.ReplicatedStorage.event2:FireClient(plr)
Return Enum.ProductPurchaseDecision.PurchaseGranted
end
end

If you say that this method not working.In my other game this method works

you can only have 1 developer product handler script in the game so if you have 2 one of them will stop working

1 Like

I made a module script that you can store products in with functions that call each time they purchase each product.

Module Script → game.ReplicatedStorage

--> Services
local Players = game:GetService("Players")

--> Class
local ProductHandler = {
	Products = {
		[PRODUCTIDHERE] = function(buyer: Player, ProductId: number)
			--> DO WHAT EVER YOU WANT TO HAPPEN WHEN THEY BUY
		end,
	}
}

--> Functions
function ProductHandler.ProductPurchased(userId, productId, wasPurchased)
	if wasPurchased == true then
		if ProductHandler.Products[productId] ~= nil then
			local Player = Players:GetPlayerByUserId(userId)
			
			if Player then
				ProductHandler.Products[productId](Player, productId)
			end
		end
	end
end

return ProductHandler

Script → game.ServerScriptService

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ProductHandler = require(ReplicatedStorage:WaitForChild("ProductHandler") --> The Module Above

local MarketplaceService = game:GetService("MarketplaceService")

MarketplaceService.PromptProductPurchaseFinished:Connect(ProductHandler.ProductPurchased)

Instead of using PromptProductPurchaseFinished i recommend to use ProcessReceipt

1 Like

I alr fixed it,so dont worry!!I fixed it

So guys,i found an sollution,i removed if plr statement,and change section of

return 
Enum.ProductPurchaseDecision.PurchaseGranted

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