Making a gui button fire a RemoteEvent and a Prompt Developer Product Purchase

I know there are many DevForum articles on this but I would like to be able to know how ProccessRecipt works without a bunch of tests, I can add them on later. How could I implement this into my code?

-- CREATE VARS --

local button = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:FindFirstChildOfClass("RemoteEvent")
local marketplace = game:GetService("MarketplaceService")
local player = game:GetService("Players").LocalPlayer
local devItemID = 1655061162

local function promptPurchase()
	marketplace:PromptProductPurchase(player, devItemID)
end

-- REMOTE EVENT --

button.MouseButton1Click:Connect(function()
	print("Buying ".. button.Name)
	promptPurchase()
end)
2 Likes

-------------CLIENT-------------------------------

local button = script.Parent
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("NAME OF YOUR REMOTE EVENT")
local MarketPlaceService = game:GetService("MarketPlaceService")
local LocalPlayer = game.Players.LocalPlayer
local devItemID_N1 = 1655061162


button.MouseButton1Click:Connect(function()
	print("Buying ".. button.Name)
	MarketPlaceService :PromptProductPurchase(LocalPlayer, devItemID_N1 )
end)

---------------------SERVER--------------------------------

local MarketPlaceService = game:GetService("MarketplaceService")
local players = game:GetService("Players")
local REP = game:GetService("ReplicatedStorage")

local devItemID_N1 = 1655061162

local function processReceipt (receiptInfo)
	
	local player = players:GetPlayerByUserId(receiptInfo.PlayerId)
	
	if not player then
		
		return Enum.ProductPurchaseDecision.NotProcessedYet
		
	end
	
	
	if player then
		
		if receiptInfo.ProductId == devItemID_N1  then
			
			--do cool things
			return Enum.ProductPurchaseDecision.PurchaseGranted
			
			
		elseif receiptInfo.ProductId ==  OTHER PRODUCT ID IF YOU HAVE MORE  then
			
		
			--dont forget the line bellow
			return Enum.ProductPurchaseDecision.PurchaseGranted			
		end
		
	end
	
end

MarketPlaceService.ProcessReceipt = processReceipt
1 Like

This helped a lot, thank you for your time!

1 Like

there is now an error that says that receipt info doesn’t exist, do I have to put the receipt info in when calling on the function like: processReceipt(put info here?)

can you provide in which line the error occurs? (with an image if possible)

sorry for replying so late, here is the error: ServerScriptService.Donate script:18: attempt to index nil with ‘PlayerId’ - Server - Donate script:18

sorry, i forgot to mention.
1

Screenshot 2023-10-01 111449
2

its on, it is erroring right here: local player = players:GetPlayerByUserId(receiptInfo.PlayerId)

Do you know what the problem is or should I create a new topic?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.