Product Purchase Finish Not Working

Hello and good evening developers,

I am currently working on a script that prompts the player with my developer product for a sword. When it is done, it is supposed to check if the purchase was a success and if so, give the player the sword. The player is prompted with the developer product purchase, but the function does not work to check. Nothing happens when I cancel and when I purchase. Any help is appreciated. Thanks!

Script:

--D00MED_S0ULL
local plr = game.Players.LocalPlayer
local Click = game.StarterGui.GUIClick
local gamepassId = 1207843619 -- All you have to do is change this to the right gamepass
local PromptCashPurchase = game.ReplicatedStorage.PromptCashPurhcase
local MarketplaceService = game:GetService("MarketplaceService")
local Sword = game.ReplicatedStorage.Tools.AzureSword

script.Parent.MouseButton1Click:Connect(function()
	Click:Play()
	MarketplaceService:PromptProductPurchase(plr, gamepassId)
	MarketplaceService.PromptPurchaseFinished:Connect(function(player, assetId, success)
		if success then
			if assetId == gamepassId then
				local Clone = Sword:Clone()
				Clone.Parent = player:WaitForChild("Backpack")
			end
		end
	end)
end)

Success returns a bool value so you would check if its true or false:

local plr = game.Players.LocalPlayer
local Click = game.StarterGui.GUIClick
local gamepassId = 1207843619
local PromptCashPurchase = game.ReplicatedStorage.PromptCashPurhcase
local MarketplaceService = game:GetService("MarketplaceService")
local Sword = game.ReplicatedStorage.Tools.AzureSword

script.Parent.MouseButton1Click:Connect(function()
	Click:Play()
	MarketplaceService:PromptProductPurchase(plr, gamepassId)
	MarketplaceService.PromptPurchaseFinished:Connect(function(player, assetId, success)
		if success == true then
			if assetId == gamepassId then
				local Clone = Sword:Clone()
				Clone.Parent = player:WaitForChild("Backpack")
			end
		end
	end)
end)
1 Like

Doesn’t “if success then” imply a check for true automatically?

This didn’t work. Like I said below, true is already implied.

Second thought, assetIds and gamepassIds aren’t the same thing, so it should work if you remove the check.

So just the first two parameters?

Yes.

if success then
local Clone = Sword:Clone()
Clone.Parent = player:WaitForChild("Backpack")
end

You just said get rid of success. Can you revise this into my script please?

--D00MED_S0ULL
local plr = game.Players.LocalPlayer
local Click = game.StarterGui.GUIClick
local gamepassId = 1207843619 -- All you have to do is change this to the right gamepass
local PromptCashPurchase = game.ReplicatedStorage.PromptCashPurhcase
local MarketplaceService = game:GetService("MarketplaceService")
local Sword = game.ReplicatedStorage.Tools.AzureSword

script.Parent.MouseButton1Click:Connect(function()
	Click:Play()
	MarketplaceService:PromptProductPurchase(plr, gamepassId)
	MarketplaceService.PromptPurchaseFinished:Connect(function(player, assetId, success)
		if success then
			local Clone = Sword:Clone()
			Clone.Parent = player:WaitForChild("Backpack")
		end
	end)
end)

As it is a developer product, you must use ProcessReceipt as this tutorial indicates.

local script
local plr = game:GetService("Players").LocalPlayer
local Click = game:GetService("StarterGui").GUIClick

script.Parent.MouseButton1Click:Connect(function()
	Click:Play()
	game:GetService("MarketplaceService"):PromptProductPurchase(plr, 1207843619)
end)
script must be in ServerScriptService.
local PromptCashPurchase = game:GetService("ReplicatedStorage").PromptCashPurhcase
local Sword = game:GetService("ReplicatedStorage").Tools.AzureSword

local Functions = {}
Functions[1207843619] = function(receiptInfo)
	local Player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
	if not Player then		return 		end
	Sword:Clone().Parent = Player:WaitForChild("Backpack")
	return true
end

game:GetService("MarketplaceService").ProcessReceipt = function(receiptInfo)
	local Product = receiptInfo.ProductId
	
	local Success, Completed = pcall(Functions[Product], receiptInfo)
	if not Success or not Completed then
		warn("Error:", Completed)
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

keep in mind if you add more products, they should all be as in table Functions and it should be like this

Functions[Id] = function(receiptInfo)
	-- code
end)

if you have multiple accessing ProcessReceipt it may not work

1 Like