Product purchase doesn't work


local player = game:GetService("Players").LocalPlayer
local ld = player:WaitForChild("leaderstats")
local damage = ld.Damage
local rebirth = ld.Rebirth

local main = script.Parent
local button = main.makeRebirth
local donateButton = main.DonateRebirth

local MPS = game:GetService("MarketplaceService")
local devproductId = 1570940043

local function donateRebirth()
	print("1")
	game:GetService("MarketplaceService").PromptProductPurchaseFinished:Connect(function(player, id, isPurchased)
		print("2")
		if (id == 1570916668) then
			print(player,id,isPurchased)
		end
	end)
end


donateButton.MouseButton1Click:Connect(donateRebirth)
donateButton.TouchTap:Connect(donateRebirth)

So this script is a local script that lies in the gui, but the problem is that when you click on the button is written only this:

I read the documentation and kind of created the product correctly, here:

but WHY doesn’t it work?

3 Likes

That event is not supported, you should use:

3 Likes

You have to actually prompt the purchase first.

Doing:

game:GetService("MarketplaceService"):PromptProductPurchase(player,devproductId)
1 Like

I believe yes you are correct, but I’m pretty sure it still works.

That event is not supported, you should use:

Where in the code should I put this?

Roblox stated over the developer page that you should use ProcessReciept, over PromptProductPurchaseFinished

Put it above this function

game:GetService("MarketplaceService").PromptProductPurchaseFinished:Connect(function(player, id, isPurchased)

Yea, let me type him a function for that.

1 Like

Very very unreliable, and its gonna make the code messy, again please use ProcessReciept

1 Like

Okay, I’ll read the documentation, thank you.

1 Like

Okay, I did it like this:

local function donateRebirth()
	print("1")
	game:GetService("MarketplaceService"):PromptProductPurchase(player,devproductId)
	game:GetService("MarketplaceService").PromptProductPurchaseFinished:Connect(function(player, id, isPurchased)
		print("2")
		if (id == 1570916668) then
			print(player,id,isPurchased)
		end
	end)
end

but as you can see the main print is not printed, so it doesn’t work, because even if I cancel the print will still be

So you’ll have to use ProcessReceipt

I’d recommend looking at this answer on it.

Okay, I wrote a script like this:

local function donateRebirth()
	print("1")
	productFunctions[1570916668] = function()
		print("donated")
	end
end

but when you click on the button, only this is displayed:

and the offer to buy does not appear at all

You need to make a β€œprocessReceipt” function to handle it.

Can I have a code example please?

Of course give me a second or two,

Okay so in your local script your going to want to do this:

local player = game:GetService("Players").LocalPlayer
local ld = player:WaitForChild("leaderstats")
local damage = ld.Damage
local rebirth = ld.Rebirth
local main = script.Parent
local button = main.makeRebirth
local donateButton = main.DonateRebirth
local devproductId = 1570940043

local function donateRebirth()
	game:GetService("MarketplaceService"):PromptProductPurchase(player,devproductId)
	if game:GetService("MarketplaceService").ProcessReceipt({PlayerId = player.UserId,ProductId = devproductId}) then --- User Purchased It
		-- Put code here
	end
end



donateButton.MouseButton1Click:Connect(donateRebirth)
donateButton.TouchTap:Connect(donateRebirth)

Then put this in a ServerScript (aka a regular Script)

local players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local debounce = false

MarketplaceService.ProcessReceipt = function(receiptInfo)
	if receiptInfo.ProductId == 1570940043 and debounce == false then

		debounce = true
		local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
		if player then

		return Enum.ProductPurchaseDecision.PurchaseGranted
		else
			return Enum.ProductPurchaseDecision.NotProcessedYet
		end
	end
end

Sorry it took so long. ( I had to use some other forums since I’ve not worked with ProcessReceipt before.)

Okay, I did as you said inserted a local script… created a global one in serverscriptService, and inserted there another script that you gave me… but. When I wrote for example print(β€œSomething”)… then it didn’t print and it gives this error when I click on it:


local function donateRebirth()
	game:GetService("MarketplaceService"):PromptProductPurchase(player,devproductId)
	if game:GetService("MarketplaceService").ProcessReceipt({PlayerId = player.UserId,ProductId = devproductId}) then --- User Purchased It
		print("Was donated")
	end
end

this print is not displayed

Going to look at it one second