MarketPlaceService.PromptPurchaseFinished not working in my module script?

Yo guys! First of all, I hope your having a great day! Now basically, I am currently trying to make a module, MarketPlaceService2 (Wow, great name), now as you probably figured, I am using the actual MarketPlaceService for this, as MSS2 (MarketPlaceService2) will basically just be MSS with more features (such as a Built-In Gamepass Gifting System). Now I am still very early in the development of this, however, when I try to detect when the ProductPurchaseFinished, it doesn’t work. Here is the relevant code:

    MSS:PromptProductPurchase(sender, productId)
	
	local connection
	connection = MSS.PromptPurchaseFinished:Connect(function(purchaser, assetId, isPurchased)
		print("Prompt Finished, bought:", isPurchased, "Asset Id:", assetId, "productId:", productId)
		if assetId == productId and isPurchased then
			-- Gift gamepass.
			connection:Disconnect()
		end
	end)

Now, the prompt fires and that works fine, however, the print statement I added in the PromptPurchaseFinished event never prints. Also for a test I tried doing just:

MSS.PromptPurchaseFinished:Connect(function(purchaser, assetId, isPurchased)
    print("Purchased")
end

Also didn’t print.

Here is the code that triggers the prompt btw:

local Players = game:GetService("Players")	
local Player = Players.LocalPlayer

local RS = game:GetService('ReplicatedStorage')
local MSS2 = require(RS.MarketPlaceService2)

local GamePassId = 68799591
local ProductId = 1293811121

script.Parent.MouseButton1Click:Connect(function()
	local PlayerToGiftTo = nil
	for _, player in Players:GetPlayers() do	
		if player == Player then continue end
		PlayerToGiftTo = player
	end
	 
	MSS2:GiftGamePass(Player, PlayerToGiftTo, GamePassId, ProductId) -- This is what fires the prompt
end)

(Local Script BTW)

I’ll try that and let you know!

This isn’t true, the problem is that they’re using PromptPurchaseFinished for developer products/gamepasses even though those asset types have their own events.

https://developer.roblox.com/en-us/api-reference/event/MarketplaceService/PromptGamePassPurchaseFinished
https://developer.roblox.com/en-us/api-reference/event/MarketplaceService/PromptProductPurchaseFinished

PromptPurchaseFinished is the event associated with purchase prompts displayed via PromptPurchase.
https://developer.roblox.com/en-us/api-reference/function/MarketplaceService/PromptPurchase

1 Like

Aha, i knew that was the wrong event however, I guess I was blind that day and didn’t see the PromptProductPurchaseFinished event on the documentation, and since I haven’t worked with MSS in a while, since the only autocompleted that showed for any PurchasedFinished thing was what I used. I’ll check it out in a minute.

For developer products it’s advised that you use the ProcessReceipt callback.
https://developer.roblox.com/en-us/api-reference/callback/MarketplaceService/ProcessReceipt

Yeah, that’s what I usually do, I was going to add that aswell. There is only 1 problem, maybe you can help, ProcessReceipt Only works on the server, correct (either way that’s more secure), however, this will be a module that anyone can use by just requiring it, however, how can I use process receipt on the server through a module script even when it was required/fired from the client?

Correct, taken from the documentation’s example of ProcessReceipt.

  1. – Set the callback; this can only be done once by one script on the server!
  2. MarketplaceService.ProcessReceipt = processReceipt

Ok, so for this case, would using PromptPurchaseFinished be better as this will be used by a function in the module while users can use PurchaseReciept for their own things?

Only the server can change the callback function assigned to ProcessReceipt.

I understand this, what I mean is:

The code you saw above will be used to make a built-in gamepass gifting function, the way it works is it will prompt a dev product, if it gets purchased then award the player receiving the gift the gamepass, however, we are calling this module from the client, so ProcessReceipt firstly won’t work and secondly if I were to use it, users not even using the GamepassGift feature won’t be able to use process receipt themselves. So for my specific use case, wouldn’t using PromptPurchaseFinished

@Forummer