Dev product ProcessReceipt isn't working

Hello Devs!

im making a troll system for my game but the ProcessReceipt fails could anyone help me?

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local SelectTarget = ReplicatedStorage:WaitForChild("SelectTarget")
local Products = require(ReplicatedStorage:WaitForChild("Presets"):WaitForChild("TrollProducts"))

-- [userId] = {target, action, productId}
local pending = {}

SelectTarget.OnServerEvent:Connect(function(player, targetUserId, action)
	if typeof(targetUserId) ~= "number" then return end
	if typeof(action) ~= "string" then return end

	local productId = Products[action]
	if not productId then return end

	local target = Players:GetPlayerByUserId(targetUserId)
	if not target then return end

	pending[player.UserId] = {
		target = targetUserId,
		action = action,
		productId = productId
	}
end)

local function ApplyEffect(target, action)
	if not target then return end

	local character = target.Character
	if not character then
		character = target.CharacterAdded:Wait()
	end

	local humanoid = character:FindFirstChildOfClass("Humanoid")
	local root = character:FindFirstChild("HumanoidRootPart")

	if action == "Kill" then
		humanoid.Health = 0

	elseif action == "Freeze" then
		root.Anchored = true
		task.delay(5, function()
			if root and root.Parent then
				root.Anchored = false
			end
		end)

	elseif action == "Fling" then
		local bv = Instance.new("BodyVelocity")
		bv.Velocity = Vector3.new(0, 200, 0)
		bv.MaxForce = Vector3.new(1e6, 1e6, 1e6)
		bv.Parent = root

		task.delay(0.5, function()
			if bv then bv:Destroy() end
		end)

	elseif action == "Explode" then
		local explosion = Instance.new("Explosion")
		explosion.Position = root.Position
		explosion.Parent = workspace

	elseif action == "Kick" then
		if target.AccountAge >= 3 then
			target:Kick("You were trolled!")
		end
	end
end

MarketplaceService.ProcessReceipt = function(receiptInfo)
	local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
	if not player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end

	local request = pending[player.UserId]

	if request and request.productId == receiptInfo.ProductId then
		local target = Players:GetPlayerByUserId(request.target)

		if target then
			ApplyEffect(target, request.action)
		end

		pending[player.UserId] = nil
	end

	return Enum.ProductPurchaseDecision.PurchaseGranted
end

Are there any errors in the console

nope none of my scripts are outputting errors.

Do you have any other scripts tha use process receipt because you can only have one script that uses it

I think I do?
let me try disabling the other scripts

nope just tried that and didnt work still :frowning:

It’s more than likely that you are using process receipt more than once you need a centralized script use the one in the documentation that’s what I did

https://create.roblox.com/docs/reference/engine/classes/MarketplaceService#ProcessReceipt

It didn’t work because the server was handling the purchase before it ever received the target/action data. My PromptProductPurchaseFinished fired too late, so ProcessReceipt ran with no matching “pending” info.

Fix was simple: send SelectTarget:FireServer() before PromptProductPurchase(), so the server already has the data when the receipt comes in.

Thanks for the help :+1: