Help with developer products & product reciepts!

So, I’m trying to make a system where players can purchase additional money through a GUI. I understand this is insanely simple however I cannot see why it’s not working as it is originally from a tutorial.

ServerScript:
image

There are no errors in the output and the cash just simply isn’t given.
I’ve tested it on the client, in studio and everything and it isn’t working.

If someone could give a fix to this relatively simple problem (lol) it would be appreciated!

2 Likes

I believe it’s receiptInfo.PlayerId, not receiptInfo.UserId. :slight_smile:

Change this:

local player = game.Players:GetPlayerByUserId(receiptInfo.UserId)

to

local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)

For future reference, the properties of ‘receiptInfo’ are shown in this documentation: MarketplaceService | Documentation - Roblox Creator Hub

1 Like

Thanks! I changed it and committed the script, published and tried however it still didn’t work…

2 Likes

You shouldn’t need to test this by publishing it all the time, you can test this kind’ve thing on Roblox Studio. :slight_smile:, what errors do you get in the console?

2 Likes

The only other thing I can think of is your receiptInfo.ProductID, I’m wondering if it’s case-sensitive and needs to be receiptInfo.ProductId instead… Try that.

1 Like

Another thing I’ve considered too is, where is that script located? The ProcessReceipt callback function wants to be declared in a server script. Stick that script in a server script in ServerScriptService.

1 Like

Yeah, it’s in SSS and it’s a server script. I tried your suggestion of changing ProductID to ProductId however that did not work.

2 Likes

Can you confirm if the product ID you’re comparing receiptInfo.ProductId with is correct too? Is that product a part of a third-party game? I’m wondering if it’s to do with that if it is.

1 Like

Nope, it’s the same in that script with the local script and it’s created under the same game.

1 Like

Are there any errors in the output that show when you try it?

1 Like

None. aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

1 Like

You should try keeping the base documentation code for it.
There was some typing errors in your script like UserId > PlayerId and ProductID > ProductId.
Also you need to do a pcall function to make sure the product was puchased, otherwise there can be a bug where people still receive the reward even when they are canceling the purchase.

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

local ProductFunctions = {}

-- Product Functions
ProductFunctions[1654837831] = function(Receipt, Player)
	local leaderstats = Player:FindFirstChild("leaderstats")
	local Money = leaderstats and leaderstats:FindFirstChild("Money")

	if Money then
		Money.Value += 250
		return true
	end
end

-- Main Functions
MarketplaceService.ProcessReceipt = function(ReceiptInfo)
	local UserId = ReceiptInfo.PlayerId
	local ProductId = ReceiptInfo.ProductId
	local Player = PlayerService:GetPlayerByUserId(UserId)

	if Player then
		local SelectedFunction = ProductFunctions[ProductId]
		local Success, Result = pcall(SelectedFunction, ReceiptInfo, Player)
		if Success then
			return Enum.ProductPurchaseDecision.PurchaseGranted
		else
			warn("Failed to process receipt:", ReceiptInfo, Result)
		end
	end
	return Enum.ProductPurchaseDecision.NotProcessedYet
end

2 Likes

Try this code, tested it on my Roblox Studio and it works fine:

game:GetService("MarketplaceService").ProcessReceipt = function(receiptInfo)
	if receiptInfo.ProductId == 1654837831 then
		local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
		if not player then
			return Enum.ProductPurchaseDecision.NotProcessedYet
		end
		
		local leaderstats = player:FindFirstChild("leaderstats")
		if not leaderstats then
			return Enum.ProductPurchaseDecision.NotProcessedYet
		end
		
		local moneyVal = leaderstats:FindFirstChild("Money")
		if not moneyVal then
			return Enum.ProductPurchaseDecision.NotProcessedYet
		end
		
		moneyVal.Value += 250
		
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
	
	return Enum.ProductPurchaseDecision.NotProcessedYet
end

It’s also important to note that you should be using PromptProductPurchase on the client. Like so:

game:GetService("MarketplaceService"):PromptProductPurchase(game:GetService("Players").LocalPlayer, 1654837831)
2 Likes

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