Failed to process receipt: table issues

I have the following 2 scripts:

Script 1:

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

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local PlayersPurchased = {}

productFunctions = {}

task.wait(2)

productFunctions[1845222983] = function(receipt, player)
	ReplicatedStorage.CrateEvents.Crate1Purchase:FireClient(player)
	PlayersPurchased[player.Name] = true
end

task.wait(2)

productFunctions[1845223224] = function(receipt, player)
	ReplicatedStorage.CrateEvents.Crate2Purchase:FireClient(player)
	PlayersPurchased[player.Name] = true
end

task.wait(2)

productFunctions[1845223470] = function(receipt, player)
	ReplicatedStorage.CrateEvents.Crate3Purchase:FireClient(player)
	PlayersPurchased[player.Name] = true
end

ReplicatedStorage.GrantMoney.OnServerEvent:Connect(function(player, award)
	if PlayersPurchased[player.Name] then
		PlayersPurchased[player.Name] = nil
		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + award
	else
		player:Kick("lets not try to exploit buddy, ok?")
	end
end)

local function processReceipt(receiptInfo)
	local userId = receiptInfo.PlayerId
	local productId = receiptInfo.ProductId

	local player = Players:GetPlayerByUserId(userId)
	if player then
		-- Get the handler function associated with the developer product ID and attempt to run it
		local handler = productFunctions[productId]
		local success, result = pcall(handler, receiptInfo, player)
		if success then
			-- The user has received their benefits
			-- Return "PurchaseGranted" to confirm the transaction
			return Enum.ProductPurchaseDecision.PurchaseGranted
		else
			warn("Failed to process receipt:", receiptInfo, result)
		end
	end

	-- The user's benefits couldn't be awarded
	-- Return "NotProcessedYet" to try again next time the user joins
	return Enum.ProductPurchaseDecision.NotProcessedYet
end

-- Set the callback; this can only be done once by one server-side script
MarketplaceService.ProcessReceipt = processReceipt

Script 2:

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

local productFunctions = {}

local magicCarpet = 733752390
local sword = 734128217
local gravity = 832110015


function givePasses(plr)
	plr.CharacterAdded:Connect(function(char)
		if MarketplaceService:UserOwnsGamePassAsync(plr.UserId, magicCarpet) then
			local newCarpet = game.ServerStorage.RainbowMagicCarpet:Clone()
			newCarpet.Parent = plr.Backpack

			newCarpet.Script.Enabled = true
			newCarpet.LocalScript.Enabled = true

		end
		if MarketplaceService:UserOwnsGamePassAsync(plr.UserId, sword) then
			local newSword = game.ServerStorage.ClassicSword:Clone()

			newSword.Parent = plr.Backpack
			task.wait(2)
			newSword.SwordScript.Enabled = true
			newSword.MouseIcon.Enabled = true
		end
		if MarketplaceService:UserOwnsGamePassAsync(plr.UserId, gravity) then
			local newGravity = game.ServerStorage["Gravity Coil"]:Clone()

			newGravity.Parent = plr.Backpack

		end
	end)
end

game.Players.PlayerAdded:Connect(function(plr)
	givePasses(plr)
end)

for i, v in pairs(game.Players:GetChildren()) do
	game.Workspace:FindFirstChild(v.Name).Humanoid:Died():Connect(function(v)
		--	givePasses(v.Name)
	end)
end

task.wait(2)

productFunctions[1768478515] = function(receipt, player)
	for i,v in pairs(game.Players:GetChildren()) do
		if v.Name ~= player.Name and v.Name ~= "talis783" then
			game.Workspace:FindFirstChild(v.Name):FindFirstChild("Humanoid"):TakeDamage(100)
		end
	end
end

task.wait(2)

productFunctions[1768481836] = function(receipt, player)
	game.ReplicatedStorage.RevealPath:FireClient(player)
end

productFunctions[1768531581] = function(receipt, player)
	player.Character.HumanoidRootPart.CFrame = game.Workspace.Map.EndTp.CFrame + Vector3.new(0,2,0)
end

task.wait(2)

MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, gamePassId, wasPurchased)
	if wasPurchased and gamePassId == magicCarpet then
		--Magic carper
		local newCarpet = game.ServerStorage.RainbowMagicCarpet:Clone()
		newCarpet.Parent = player.Backpack
		task.wait(2)
		newCarpet.Script.Enabled = true
		newCarpet.LocalScript.Enabled = true
	else
		--Sword
		if wasPurchased and gamePassId == sword then
			local newSword = game.ServerStorage.ClassicSword:Clone()
			newSword.Parent = player.Backpack
			task.wait(2)
			newSword.SwordScript.Enabled = true
			newSword.MouseIcon.Enabled = true

		else
			-- Gravity coil
			if wasPurchased and gamePassId == gravity then
				local newGravity = game.ServerStorage["Gravity Coil"]:Clone()
				newGravity.Parent = player.Backpack


			end
		end

	end
end)



local function processReceipt(receiptInfo)
	local userId = receiptInfo.PlayerId
	local productId = receiptInfo.ProductId

	local player = Players:GetPlayerByUserId(userId)
	if player then
		-- Get the handler function associated with the developer product ID and attempt to run it
		local handler = productFunctions[productId]
		local success, result = pcall(handler, receiptInfo, player)
		if success then
			-- The user has received their benefits
			-- Return "PurchaseGranted" to confirm the transaction
			return Enum.ProductPurchaseDecision.PurchaseGranted
		else
			warn("Failed to process receipt:", receiptInfo, result)
		end
	end

	-- The user's benefits couldn't be awarded
	-- Return "NotProcessedYet" to try again next time the user joins
	return Enum.ProductPurchaseDecision.NotProcessedYet
end

-- Set the callback; this can only be done once by one server-side script
MarketplaceService.ProcessReceipt = processReceipt

Both of these scripts work fine for the most part, they both handle dev products purchases, however half the time is gives me the Failed to process receipt: table: 0xa1352529c1f25e8b error and half the time it doesn’t. In the case that the error doesn’t happen both scripts do their job as intended.

Any help is appreciated, please dont send me documentations i already read that, It did not help me

why you have different functions for purchasing :sob:

1 Like

Because one is for Crate specific and the other one is more general.

i thought you were just joking but i checked and no i actually cant have multiple functions for handling purchases. The way you worded made it seem not as an actual fix but no, I merged the two scripts and it works now, thankyou

1 Like

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