How to confirm a purchase on a developer product

Hi there! I am testing out a product for my game. I need to confirm whether a person has bought that product. Right now, my code is

local ui = script.Parent	
local button = ui.TextButton
local nuke = false

local Players = game:GetService("Players")

local MS = game:GetService("MarketplaceService")
local nukeID = XXXXXX
local nukeinfo = MS:GetProductInfo(nukeID, Enum.InfoType.Product)

local function promptPurchase()
	local player = Players.LocalPlayer
	MS:PromptProductPurchase(player, nukeID)
end



local function onclick()
	if nuke == false then
		promptPurchase()
		print("POSSIBLE NUKE TIME ")
		
		
	else 
		button.Text = "Nuke is disabled"
		print("Nope nuke is active")
		nuke = false
	end
end

button.Activated:Connect(onclick) 

I need it to confirm the purchase, and print NUKE TIME!
This code doesn’t work, anyone know why?

if nuke == false then
   promptPurchase()
   print("POSSIBLE NUKE TIME")
      if Enum.ProductPurchaseDecision.PurchaseGranted == true then
             print("NUKE TIME!")
(else if part)

end

end
2 Likes

This line basically does nothing. You’re comparing an enum with a boolean. Please look at this page, it might help your case.

Thanks, but how do I confirm if the purchase is true?

local function gamepassPurchaseFinished(player, id, bought)
      if id == nukeID then --We check if the gamepass is the gamepass we need to check.
          if bought then --We check if the player bought the gamepass.
              print("NUKE TIME!")
          else
              --The purchase was canceled.
          end
      end
end

MS.PromptGamePassPurchaseFinished:Connect(gamepassPurchaseFinished)

Something like this. Hope it helped.

I’ve now encountered another problem that I’ve been trying to solve for the past half hour. This is my code:

local MS = game:GetService("MarketplaceService")

local Players = game:GetService("Players")

local nukeID = 1131145404
local nuke = false 

local ui = script.Parent
local button = ui.TextButton

local function promptPurchase()
	local player = Players.LocalPlayer
	MS:PromptProductPurchase(player, nukeID)
end

local function onclick()
if nuke == false  then
	promptPurchase()
	print("POSSIBLE NUKE TIME ")
		


else 
	button.Text = "Nuke is online"
	end
end

local function gamepassPurchaseFinished(player, id, bought)
	if id == nukeID then --We check if the gamepass is the gamepass we need to check.
		if bought then --We check if the player bought the gamepass.
			print("NUKE TIME!")
		else
			--The purchase was canceled.
		end
	end
end



if button.Activated:Connect(onclick) then
	MS.PromptPurchaseFinished:Connect(gamepassPurchaseFinished)
end 

I want it to confirm the purchase if the client presses the button, AND buys the product, but the above code won’t work. Any suggestions?

You can use MarketplaceService.ProcessReceipt (in a server script)

for example:

local mkps = game:GetService("MarketplaceService")
local ProductId = 0


local function processReceipt(receiptInfo)
    local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
    if not player then
        return Enum.ProductPurchaseDecision.NotProcessedYet
        
    elseif player then
        if receiptInfo.ProductId == ProductId then
            print("Success")
        end
        return Enum.ProductPurchaseDecision.PurchaseGranted
    end
end

mkps.ProcessReceipt = processReceipt

and on a local script

local player = game.Playera.LocalPlayer

game:GetService("MarketPlaceService"):PromptProductPurchase(player, 0)

it will print “Success” when player buys the 0 product

12 Likes

I’m assuming the error is with the fact that you use PromptPurchaseFinished as a function call with MS.PromptPurchaseFinished instead of a method call MS:PromptPurchaseFinished.

Also, please read what AtomTostcuOzgurUsta said above, as on the developer page for PromptPurchaseFinished, it says you should use ProcessReceipt instead.

3 Likes

Ummmm i believe it is Players and not Playera

(joke)