How to keep critical data with ProcessReceipt?

Hello, I have a feature in my game where you can buy a Dev Product to troll a player that you choose (each troll is its own product), and Im using ProcessReceipt to make sure the player bought the product ( as is standard practice).

When it fires the callback and if you bought the product it fires a bindable event to my Troll server script that will do all the functions. Only thing is when I prompt the purchase the only info I can send is related to the product itself, so all the extra info (troll name, player you selected) is lost so I cant actually run the troll.

In my local script when you choose a troll and a player it fires a remote event with said data and that server script that picks up the event prompts the purchase

buyTroll:FireServer(choicePlayer, selectedTroll) --local

buyTroll.OnServerEvent:Connect(function(player, choicePlayer, selectedTroll)
	--print(player, choicePlayer, selectedTroll)
	local devId = list.RobuxProducts.Trolls[selectedTroll]
	MarketplaceService:PromptProductPurchase(player, devId)
end)

–Server Troll Script

In my process purchase server script

MarketplaceService.ProcessReceipt = function(receiptInfo, extraInfo)
    --other products
    local trollList = List.RobuxProducts.Trolls
	
	for name, id in trollList do
		if productId == id then
			ReplicatedStorage.Events.Players.Hiders.trolls:WaitForChild("FireTroll"):Fire(name) --fire to troll script
			return Enum.ProductPurchaseDecision.PurchaseGranted
		end
	end
end

The issue here is now that once the receipt is processed successfully it lost all of the data needed like the player selected.

trollActivated.Event:Connect(function(trollName)
	--only trollName can be sent 
	
end)

I know this is quite long but I have no idea how im supposed to get said player that was chosen in the buyTroll event. If anyone has any idea please let me know, thanks.

1 Like

You shouldn’t need a remote to handle the client buying the product, you can handle promptpurchase on the client, and on the server you can pick that up and process the Receipt. For getting the data across, you can use a bindable event, and when the receipt is processed and validated, invoke the client requesting the player they want to troll. An approach like this is what I would recommend

Server

local ms = game:GetService("MarketplaceService")
local ps = game:GetService("PlayerService")
local requestPlayerEvent:BindableEvent = nil -- up to you
ms.ProcessReceipt = function(info)
    -- do ur code here to detect the correct product, im just assuming here 
    -- that its the troll one
    local plr = ps:GetPlayerByUserId(info.PlayerId)
    local result = requestPlayerEvent:InvokeClient(plr)
    if result and result:IsA("Player") and result~=plr then
        -- now you can handle the troll code here
    end
end

Client

local bindable:BindableEvent = nil -- again, up to you

bindable.onClientInvoke = function()
    return shared.selectedPlayer -- you don't have to do this, but if you have no other way of getting the selected player, you can set/get a shared value
end