ProcessReceipt only works in Studio Play

Hi! I need help on how to process the receipt after a player buys a DevProduct.
I know there are better/easier ways of doing this, but this is actually one of my first systems that I tried to make myself with little help…

So everything here works, but there is a part that only works in Studio Solo Play.
I will explain in comments what everything does.

This ServerScript runs after a LocalScript inside a Button fires the Remote Event (this works both in Studio and In-Game):

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MarketplaceService = game:GetService("MarketplaceService")
local gamepassPromptEvent = ReplicatedStorage.Events.GamepassPromptEvent
local devproductPromptEvent = ReplicatedStorage.Events.DevProductPromptEvent

gamepassPromptEvent.OnServerEvent:Connect(function(player, id) --Fires if player clicks on a button to buy a gamepass
	MarketplaceService:PromptGamePassPurchase(player, id) --Prompts GamePass
	print("Gamepass Prompted!")
end)

devproductPromptEvent.OnServerEvent:Connect(function(player, id) --Fires if player clicks on a button to buy a devproduct
	MarketplaceService:PromptProductPurchase(player, id) --Prompts DevProduct
	print("DevProduct Prompted!")
end)

After the player closes the purchase prompt this ServerScript runs (this works both in Studio and In-Game):

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

local purchaseFinishedEvent = ReplicatedStorage.Events:WaitForChild("PurchaseFinishedEvent")
local purchaseUnfinishedEvent = ReplicatedStorage.Events:WaitForChild("PurchaseUnfinishedEvent")

MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, assetId, isPurchased) --After player closes the game pass prompt do
	if isPurchased then --If player bought the game pass do
		purchaseFinishedEvent:FireClient(game.Players:GetPlayerByUserId(player)) --Fire localscript that makes a message appear
		print(game.Players:GetPlayerByUserId(player).Name.." bought GamePass with AssetID: "..assetId)
	else --If player didn't buy the game pass do
		purchaseUnfinishedEvent:FireClient(game.Players:GetPlayerByUserId(player)) --Fire localscript that makes a message appear		
		print(game.Players:GetPlayerByUserId(player).Name.." didn't buy GamePass with AssetID: "..assetId)
	end
end)

MarketplaceService.PromptProductPurchaseFinished:Connect(function(player, assetId, isPurchased) --After player closes the devproduct prompt do
	if isPurchased then --If player bought the devproduct do
		purchaseFinishedEvent:FireClient(game.Players:GetPlayerByUserId(player)) --Fire localscript that makes a message appear
		print(game.Players:GetPlayerByUserId(player).Name.." bought DevProduct with AssetID: "..assetId)
	else --If player didn't buy the devproduct do
		purchaseUnfinishedEvent:FireClient(game.Players:GetPlayerByUserId(player)) --Fire localscript that makes a message appear
		print(game.Players:GetPlayerByUserId(player).Name.." didn't buy DevProduct with AssetID: "..assetId)
	end
end)

Everything until here works perfectly fine!

This next ServerScript only works perfectly on Studio Solo Play/Test. It doesn’t do nothing in Studio Team Test or In-Game.
I know this because the function only prints and the values only change when I’m in Studio Solo Play…

local marketPlaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local flingevent = ReplicatedStorage.Events.FlingEvent

marketPlaceService.ProcessReceipt = function(receiptInfo)
	print("test")
	local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
	
	if receiptInfo.ProductId == ~DevProductIdHere~ then
		player.values.Skips.Value = player.values.Skips.Value + 1
		return Enum.ProductPurchaseDecision.PurchaseGranted
		
	elseif receiptInfo.ProductId == ~DevProductIdHere~ then
		player.values.Skips.Value = player.values.Skips.Value + 3
		return Enum.ProductPurchaseDecision.PurchaseGranted
		
	elseif receiptInfo.ProductId == ~DevProductIdHere~ then
		player.values.Skips.Value = player.values.Skips.Value + 5
		return Enum.ProductPurchaseDecision.PurchaseGranted
		
	elseif receiptInfo.ProductId == ~DevProductIdHere~ then
		flingevent:Fire()
		return Enum.ProductPurchaseDecision.PurchaseGranted	
	end
end

Can someone help me?

You should include your product ids so it’s easier for people to help you.

Replace your second script with this:

--//Services
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--//Variables
local flingevent = ReplicatedStorage.Events.FlingEvent

--//Tables
local productFunctions = {}

--//Functions
productFunctions[000000] = function(reciept, player)
	--//Gives 1 skips
	player.values.Skips.Value += 1

	return true
end

productFunctions[000000] = function(reciept, player)
	--//Gives 3 skips
	player.values.Skips.Value += 3

	return true
end

productFunctions[000000] = function(reciept, player)
	--//Gives 5 skips
	player.values.Skips.Value += 5

	return true
end

productFunctions[000000] = function(reciept, player)
	--//Flings
	flingevent:Fire()

	return true
end

MarketplaceService.ProcessReceipt = function(receiptInfo)
	local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)

	if not player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end

	local Function = productFunctions[receiptInfo.ProductId]

	local success, result = pcall(Function, receiptInfo, player)

	if not success or not result then
		warn("Error occurred while processing a product purchase")
		print("\nProductId:", receiptInfo.ProductId)
		print("\nPlayer:", player)

		return Enum.ProductPurchaseDecision.NotProcessedYet
	end

	return Enum.ProductPurchaseDecision.PurchaseGranted
end

Replace all the product ids with your own.

1 Like

Try setting the callback at the end of the ProcessReceipt script:

MarketplaceService.ProcessReceipt = processReceipt
1 Like

That would do the exact same thing as his other script. Connecting a function manually, or calling it later, will do the same thing.

2 Likes

The script did work in Studio Play (gave me the skips and fired the event), but doesn’t do anything if I’m in Studio Team Test…
Also ty for the tips, and I will try to get used to formatting my scripts like that…

Hm, that’s weird. Are you sure you enabled sales in game settings? It works for me.

1 Like

Like I think everything is alright… The only thing that isn’t enabled in Game Settings is the 3rd party sales, 3rd party teleports and https requests options…

I don’t know why, but maybe you have to enable this for team testing? I don’t know how it would only work on studio, but not on a team test.

1 Like

I enabled it and it’s still not working… No errors too!

I added print here and it only prints in Solo Play, even with or without the options turned on…
I’m searching for what is causing the problem for quite a while now and I still didn’t find anything that could be causing this!

Did you check the ‘Server’ tab of the ‘Developer Console’ when looking for outputs?

2 Likes

Nothing

One of the problems could be two scripts using ProcessReceipt, but that’s not the case…

Only one script should be ProcessReceipt I think

1 Like

That’s right, but there is only one script using ProcessReceipt!

1 Like