Issues with possibly MarketplaceService

I’m facing an issue with getting the “MarketplaceService.ProcessReceipt” to fire. I fires roughly 10% of the time and prints out the player who bought the developer product (the first 2 prints on the serversided script). I have tried multiple different methods to get it to fire 100% of the times but failed all the times and I have no clue on what is wrong… If I join the game in studio, it will sometimes print everything out, while leaving the game and joining back and havent editted in the script it wont print it all out. If anyone knows what is wrong please give me feedback!
Picture1
Picture2

I have uploaded screenshots of what the output says…

Client-sided (completely functions)
local marketplace = game:GetService("MarketplaceService")
local players = game:GetService("Players")

local rp = game:GetService("ReplicatedStorage")
local button = script.Parent
local deathmsg = button.Parent.Parent:WaitForChild("DeathMessage")
local id = 1174436046

button.Activated:Connect(function()
	print("0.5")
	marketplace:PromptProductPurchase(players.LocalPlayer, id)
	print("0.6")
end)

rp:WaitForChild("KillAll").OnClientEvent:Connect(function(playerName)
	deathmsg.Text = playerName .. " killed  everyone!"
	deathmsg.Visible = true
	wait(5)
	deathmsg.Visible = false
end)
Server-sided (Issue)
local MarketplaceService = game:GetService("MarketplaceService")
local PlayerService = game:GetService("Players")

local rp = game:GetService("ReplicatedStorage")

local id = 1174436046

local function Process(Info, plr)
	wait(1)
	print(Info.PlayerId)
	local plrId = PlayerService:GetPlayerByUserId(Info.PlayerId)
	print(plrId)

	if not plrId then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end

	if Info.ProductId == id then
		for i, v in pairs(PlayerService:GetPlayers()) do
			if v ~= plrId then
				local character = v.Character
				if v.Character then
					print("working")
				end 
			end	
		end
end


	return Enum.ProductPurchaseDecision.PurchaseGranted
end

MarketplaceService.ProcessReceipt = Process

1 Like

I can’t see the error in the second picture. Could you take another picture and make it larger?

1 Like

That’s not an error related to the script, It is just a “failed to load sound error”

1 Like

oh ok. So it just sometimes doesn’t fire at all?

1 Like

Yep, and I have no idea why if its a roblox related issue or some other…

1 Like

The fact that it fires from time to time sounds like you have multiple such scripts each with its own ProcessReceipt. You may only have one per place.

1 Like

That is true I do use multiple ProcessReceipts… but how do I use the other gamepasses in my game then?

1 Like

In your process receipt function, you can have functions linked to IDs. For example

-- in ProcessReceipt function:

if productFunctions[id] then
	productFunctions[id]()
end

-- while having a table/module with those functions and IDs as keys.

local productFunctions = {
	[123456789] = function()
		-- continue here
	end;
	[987654321] = SomeModule.DoThisAndThat;
}

Of course, you can also pass arguments to those functions. You have a lot of freedom from here on, so you can adjust this to your liking/framework.

You can only have one ProcessReceipt, and have it call appropriate functions. Then you can diversify your code.

2 Likes

Okay thank you for clarifying the ProcessReceipt!

2 Likes

No problem! If I can be of any further assistance, my DMs are open too. I totally forgot that if-statements can also do the trick, but they’re by nature not as neat as tables in this case.

if id == ... then
	function1()
elseif id == ... then
	function2()
elseif ... then
	...
end
1 Like

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