How to detect if player cancel or puchase a Devproduct

Hi,

I’m making a donation gui and I wanted to add a loading screen when a player chooses to purchase
I wanted to detect if the player cancels or purchases the product.

I used PromptPurchaseFinished but it doesn’t work
It’s in a localScript

Script:

local function setUp(inst,devID)
	inst.MouseButton1Click:Connect(function()
		MPS:PromptProductPurchase(plr, devID)
		tween:Play() -- fade in tween
	end)
	
	MPS.PromptPurchaseFinished:Connect(function(plr, assetID, bool) -- doesn't work :(
		if bool then
			print("buy")
			done:Play() -- fade out tween
		else
			print("cancel")
			done:Play()
		end
	end)
	
end

Thanks

2 Likes
local MarketplaceService = game:GetService("MarketplaceService")
 
MarketplaceService.PromptPurchaseFinished:Connect(function(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)

if you add this in a server script then everytime a player makes a purchase inside your game, the function would run. so you need to put it in a server script then handle the tweening in the server side by player.PlayerGui.YourGui or use a remote event.

more info: MarketplaceService.PromptPurchaseFinished

2 Likes

it doesn’t print even in script

1 Like

add it in a separate script, and then handle the tweening there or use a remote event to handle it in a local script

1 Like

that’s what i did i made a separate script still doesn’t prints
it’s located in serverscriptservice

can i see the new script? or is it exactly this one

1 Like


image

1 Like

that one is different that’s a local script located in startergui

can you try doing this and see if it would print pass?

local MarketplaceService = game:GetService("MarketplaceService")
 
MarketplaceService.PromptPurchaseFinished:Connect(function(player, assetId, isPurchased)
    print("pass")
	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)
1 Like


it didn’t print

also does it work in devproducts?

oh, if you want to make something for devproducts do this

local prodId = 1
MarketplaceService.ProcessReceipt = function(receiptInfo) 
    -- find the player based on the PlayerId in receiptInfo
    for i, player in ipairs(game.Players:GetChildren()) do
        if player.userId == receiptInfo.PlayerId then
            -- check which product was purchased (required, otherwise you'll award the wrong items if you're using more than one developer product)
            if(tonumber(receiptInfo.ProductId) == prodId)then
               --Your function HERE
            end
        end 
    end
    -- tell ROBLOX that we have successfully handled the transaction (required)
    return Enum.ProductPurchaseDecision.PurchaseGranted     
end

source: https://scriptinghelpers.org/questions/4613/how-do-you-give-a-player-who-buys-a-developer-product-an-item

1 Like

does it work in local script or only in server scripts?

it should be in a serverscript inside the serverscriptservice

1 Like
local marketplace = game:GetService("MarketplaceService")

marketplace.PromptProductPurchaseFinished:Connect(function(userId, productId, wasPurchased)
	if wasPurchased then
		print("Success!")
	else
		print("Fail!")
	end
end)

Don’t use this to verify if a developer product was purchased but use this if you need an event which is fired whenever a developer purchase prompt is closed.

5 Likes

Why can’t it be used to verify if a product was purchased?