How to detect if a product is purchased instantly

So i am trying to make a purchase system that detects immediately after its purchased and not when you press the OK button, i dont really have a screenshot atm but i want to detect when you click the purchase button and it validates the purchase and not when clicking the OK button right after you purchased it.

i tried everything but couldnt do what i wanted to do

this is so that if a player gets disconnected right after making the purchase they dont get scammed, how can i do this?

1 Like

how they get scammed if they leave immediately after the purchase , also no one is going to leave the game after purchasing any thing immediately they may get disconnected , you can save the purchase in datastore so if the any player purchase a developer product and then disconnected it will be saved that player purchase that item and did not use it

Not something I work with much right now, but I think pcalls prevent you accidentally giving them an item if they get disconnected immediately after purchase.

no they do not , pcalls just prevent the code from throwing errors

Yes I know, but for purchasing developer products wouldn’t the pcalls success be false with a reason saying player left?

if not then what about the ProcessReceipt thing?

1 Like

no it will not , it will return false if it failed to prompt the user to buy the product

ProcessReceipt in an event it will fire when a player try to buy a developer product , it gives you a ReceiptInfo table , you need to return an Enum.ProductPurchaseDecision to the event , you do not need to wrap this in a pcall

pcall stands for “Protected Call” all it is job is to do not let the code inside to throw errors

But used to prevent serious failures and usually for API kind of stuff.

1 Like

yes , in this case it will return false if it failed to prompt the user to purchase the developer product

Possibly PromptProductPurchaseFinished

local MarketplaceService = game:GetService("MarketplaceService")

local function onPromptPurchaseFinished(player, assetId, isPurchased)
	if isPurchased then
		print(player.Name, "bought an item with AssetID:", assetId)
	else
		print(player.Name, "didn't buy an item with AssetID:", assetId)
	end
end

MarketplaceService.PromptPurchaseFinished:Connect(onPromptPurchaseFinished)