Developer Product Fails, new error?

Hello all,

I’ve been noticing something new I guess? And that is my developer product codes no longer function properly, and they had prior to the recent studio update. The print prints nothing, and there’s no “Cash” being awarded. I don’t understand exactly as to why, and would like some feedback if anyone sees anything right out the gate that could be the issue!

Any and all help/feedback is appreciated! Ty :slight_smile:

local mps = game:GetService("MarketplaceService")

local cash_100 = 1117585993
local cash_150 = 1117586411
local cash_1000 = 1117586121
local cash_1500 = 1117586551

local function processRecipet(receiptInfo)
	local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
	
	if not player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	
	if receiptInfo.ProductId == cash_100 then
		if player then
			player.stats.Cash.Value = player.stats.Cash.Value + 100
			print(player.Name.." bought "..receiptInfo.ProductId)
		end
	end
		
	if receiptInfo.ProductId == cash_150 then
		if player then
			player.stats.Cash.Value = player.stats.Cash.Value + 150
		end
	end
		
	if receiptInfo.ProductId == cash_1000 then
		if player then
			player.stats.Cash.Value = player.stats.Cash.Value + 1000
		end
	end
			
	if receiptInfo.ProductId == cash_1500 then
		if player then
			player.stats.Cash.Value = player.stats.Cash.Value + 1500
		end	
	end
	
	
	
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

mps.ProcessReceipt = processRecipet
1 Like

Firstly, why are you checking in each statement if the player exists when it already did that check before, I don’t think it’s necessary. Secondly

If you’re using Roblox’s built in Leaderboard system, the name of the folder should be called leaderstats not stats

1 Like

I am using my own leaderstats system and the folders name is “stats”. The player check repeat I agree isn’t necessary.

I think this is the issue, remove the ()

1 Like

Attempted this as well to no avail.

Hmm, then I think what you should do is use the code in https://developer.roblox.com/en-us/api-reference/callback/MarketplaceService/ProcessReceipt as a reference to how you should create your processReceipt since it could be the way you wrote the code

1 Like

I have reviewed that section of code given in the API, and haven’t found a problem related to mine.

Hmm, maybe it could be something related to incorrect IDs? Try printing the receiptInfo’s ProductId and see if it prints. If it doesn’t, then there may be antoehr script tampering with the processReceipt

1 Like

It prints nothing. There’s nothing messing with anything from what I can see anyway as well. I also inputted the method used in the api, changed hte necessary strings and such, and it still didn’t properly function. Could this be a studio or game bug?

Try doing Ctrl + Shift + F and search for processReceipt. Do you by any chance have a donation board in your game?

1 Like

Yes. I wasn’t informed of this… That must be the problem? I don’t know exactly. I wasn’t aware they messed with anything I thought it was a separate thing.

So you have a donation board in your game? That’s the issue then, you can only have one script giving the ProcessReceipt callback. That’s why it wasn’t pritning anything, because the donation board is using it, you have to make it work with your processreceipt instead, which is not that difficult. If needed, I could do that for you and explain the process

1 Like

Sure! If you wouldn’t mind. Lovely to know. I will accept that as the Solution.

Basically, the first thing you have to do is to get the code the Board gives, you can do that by play testing, going in the explorer and finding the script that has just been added that contains the information for its processreceipt, you can tell which script it is via the GetData function. Copy the code that has a lot of if statements and stop play testing.

Now, to disable its proecssReceipt, go into the Boards model and click on the Products Modulescript, where you input the information about your donation Dev Products, there’s a commented line called ``module.AbortCustomPurchases = true`, uncomment it by removing the –

Now to make it work with your system, you’ll have to do a bit of editing with your script to make it compatible, which should look something like

local mps = game:GetService("MarketplaceService")
local products = require() --In the brackets insert where your board's products modulescript is located
local productshandler = {}

productshandler[1117585993] = function(receiptInfo,player)
	player.stats.Cash.Value += 100 --Short hand for player.stats.Cash.Value = player.stats.Cash.Value + 100
    return true
end

productshandler[1117586411] = function(receiptInfo,player)
	player.stats.Cash.Value += 150
    return true
end

productshandler[1117586121] = function(receiptInfo,player)
	player.stats.Cash.Value += 1000
    return true
end

productshandler[1117586551] = function(receiptInfo,player)
	player.stats.Cash.Value += 1500
    return true
end


local function processRecipet(receiptInfo)
	local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
	
	if not player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	
	local handle = productshandler[receiptInfo.ProductId] --Get the function connected to that ProductId
	
	local success,result = pcall(handle,receiptInfo,player) -- Run the function if it exists
	
	if not success or not result then --If the function didn't exist, assume it's a donation product
		local PlayerFound = false
		for i, v in pairs (game.Players:GetChildren()) do
			if v:IsA('Player') then
				if v.userId == receiptInfo.PlayerId then
					for _, p in pairs (products.Products) do
						if p.ProductId == receiptInfo.ProductId then
							if v ~= nil then
								PlayerFound = true
								game:GetService("DataStoreService"):GetOrderedDataStore("TopDonators"):IncrementAsync(receiptInfo.PlayerId, p.ProductPrice)
							end
						end
					end
				end
			end
		end
		if PlayerFound ~= true then
			return Enum.ProductPurchaseDecision.NotProcessedYet        
		end
	end
	
	
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

mps.ProcessReceipt = processRecipet

Edit: Keep in mind that if you hae another dev product that you did not include in the producthandler table, it will assume that it is a donation dev product, which an be easily fixed by tweaking the if statements around or adding it to the producthandler table

9 Likes

Excellent! Thank you! :slight_smile:

character limit is annoying

Glad I was able to help out! Please tell me if the code has some issues if you’ve tried it so I can help out!

1 Like