Problem with dev products

Hello, I am making a game with dev products and I have a module that is supposed to return if you complete the purchase. I’m not sure how to make it work correctly. The problem is that it is not waiting for the actual purchase to be complete. I’m not sure how to fix this.

local marketModule = {}

function marketModule.handleProductPurchase(player, ID, productType)
	local isProcessComplete = false

	MarketplaceService:PromptProductPurchase(player, ID)

	local function ProcessReceipt(ProductInfo)
		local _player = Players:GetPlayerByUserId(player.UserId)
		
		if not _player then
			return Enum.ProductPurchaseDecision.NotProcessedYet
		end

		isProcessComplete = true
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
	MarketplaceService.ProcessReceipt = ProcessReceipt

	return isProcessComplete
end
return marketModule

Here is the module. Thanks! Any help is appreciated

Hey there! :wave:

You need to use PromptProductPurchaseFinished for this instead of ProcessReceipt! Let me know if this is of any assistance. :grinning_face_with_smiling_eyes:

It says that its deprecated. I’m not sure if it is worth it to use that.

PromptProductPurchaseFinished is only deprecated to discourage developers from using it to grant purchases instead of ProcessReceipt, which has happened and still does happen sometimes. The event isn’t actually deprecated and you need to use it. There’s no other way to do this.

Don’t make a function that is called everytime a purchase is made! You are basically overwriting the callback function everytime.

Instead, it should be only called once. Make a separate script to handle the purchases.

2 Likes
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local marketModule = {}
local isProcessComplete = false

local function ProcessReceipt(ProductInfo)
	local _player = Players:GetPlayerByUserId(ProductInfo.PlayerId)

	if not _player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end

	isProcessComplete = true
	return Enum.ProductPurchaseDecision.PurchaseGranted
end
MarketplaceService.ProcessReceipt = ProcessReceipt

function marketModule.handleProductPurchase(player, ID, productType)

	MarketplaceService:PromptProductPurchase(player, ID)


	return isProcessComplete
end

return marketModule

Here is a different version. I don’t totally understand what you mean. Can I maybe have an example?

When you want to perform a product purchase, don’t call a function to which you expect a response. Instead, directly call the marketplace service PromptProductPurchase method, and do the rest in ProcessReceipt.

MarketplaceService.ProcessReceipt = function(receipt)
	local player = Players:GetPlayerByUserId(receipt.PlayerId)
	ReplicatedStorage.RemoteEvent:FireClient(player, ...) -- something
	return Enum.ProductPurchaseDecision.NotProcessedYet -- or whatever
end

local marketModule = {}

function marketModule.makeProductPurchase(player, ID)
	return MarketplaceService:PromptProductPurchase(player, ID)
end
1 Like

I’m going to try that. It looks like it will work fine. Thanks for the help