Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I have a question about ProcessReceipts and RemoteEvents?

So I browsed the wiki to find this script that processes multiple developer products. So, I made multiple buttons that each contain a BuyScript, which prompts a player if they would like to buy the developer product. It works, but the problem is processing that they bought it so they can get xp for buying it. How could I connect a RemoteEvent to each BuyScript in each button that connects to the ReceiptProcessor script? Would I need multiple events? I need some help, I've been struggling with this all day.

1 answer

✓ Accepted answer

MarketplaceService.ProcessReceipt is a function that fires whenever PromptProductPurchase is called(and accepted) on a player. It can only be defined on the server.. so you don't need to worry about Remotes.

When fired, it returns a dictionary of the receipt's "info". You can check the ProductId index, and compare it to decide which Product the player has purchased. Check the PlayerId index, and compare it using the GetPlayerByUserId function to decide which player to award.

This is essentially how it would be setup:

StarterGui

ScreenGui

TextButton

LocalScript ::

local plr = game.Players.LocalPlayer --The client
local ms = game:GetService("MarketplaceService")
local id = 000000 --ID of product to prompt

script.Parent.MouseButton1Down:Connect(function() --When player clicks button
	ms:PromptProductPurchase(plr,id) --Prompt the product
end)

ServerScriptStorage

Script ::

local id1 = 00000000 --first product
local id2 = 00000001 --second product

function game:GetService("MarketplaceService").ProcessReceipt(receiptInfo)
	--PlayerId index of receiptInfo
	local plr = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
	--ProductId index of receiptInfo
	local product = receiptInfo.ProductId
	--Compare product
	if product == id1 then

		--award1 to 'plr'

	elseif product == id2 then

		--award2 to 'plr'

	end
	--Remember to return PurchaseGranted to get your money!
	return Enum.ProductPurchaseDecision.PurchaseGranted		
end

2 comments

0

Yes, but I have like 10 buttons. How could I do it with more than 2?

0

Nevermind, I figured it out. You're a life saver!!!! Upvote and accepted answer!!!

This discussion is preserved as it was. New answers, comments, and votes are closed.