Developer Product script broke on its own

Hi, I was using a developer product script that I’ve used before in a different game of mine, just with new IDs. It was working just fine until a day or two ago, and we didn’t change any code whatsoever. My client even tested the product in normal Roblox Player by setting the price to zero and it still didn’t award the product. Here’s the script:


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

-- Data store for tracking purchases that were successfully processed
local purchaseHistoryStore = DataStoreService:GetDataStore("PurchaseHistory")

-- Table setup containing product IDs and functions for handling purchases
local productFunctions = {}
productFunctions[1130552603] = function(receipt, player)
	player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 50
	return true
end
productFunctions[1130553264] = function(receipt, player)
	player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 125
	return true
end
productFunctions[1130553322] = function(receipt, player)
	player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 275
	return true
end

-- The core 'ProcessReceipt' callback function
local function processReceipt(receiptInfo)

	-- Determine if the product was already granted by checking the data store  
	local playerProductKey = receiptInfo.PlayerId .. "_" .. receiptInfo.PurchaseId
	local purchased = false
	local success, errorMessage = pcall(function()
		purchased = purchaseHistoryStore:GetAsync(playerProductKey)
	end)
	-- If purchase was recorded, the product was already granted
	if success and purchased then
		return Enum.ProductPurchaseDecision.PurchaseGranted
	elseif not success then
		error("Data store error:" .. errorMessage)
	end

	-- Find the player who made the purchase in the server
	local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
	if not player then
		-- The player probably left the game
		-- If they come back, the callback will be called again
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end

	-- Look up handler function from 'productFunctions' table above
	local handler = productFunctions[receiptInfo.ProductId]

	-- Call the handler function and catch any errors
	local success, result = pcall(handler, receiptInfo, player)
	if not success or not result then
		print(success)
		print(result)
		warn("Error occurred while processing a product purchase")
		print("ProductId: ", receiptInfo.ProductId)
		print("Player: ", player)
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end

	-- Record transaction in data store so it isn't granted again
	local success, errorMessage = pcall(function()
		purchaseHistoryStore:SetAsync(playerProductKey, true)
	end)
	if not success then
		error("Cannot save purchase data: " .. errorMessage)
	end

	-- IMPORTANT: Tell Roblox that the game successfully handled the purchase
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

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

And yeah, I’m pretty sure this code is from the Developer Hub, which makes it even more puzzling why it’s breaking.

When I print success and result, success returns false and result returns “attempt to call a nil value”, and this definitely did not happen before January 1.

Any clue how it broke on its own? Any errors or deprecated code somewhere? Any help would be appreciated, we’re looking to release very soon.

1 Like

If it isn’t a script error then it is the developer products, re-check it if you see any problems like if it’s not on sale.

1 Like

Yeah, nothing was changed with any of that stuff, I even re-entered the IDs for the Products yesterday. Still giving the “attempt to call a nil value” problem and success is false.

The sale is 0 robux so it’s nil?

That would make sense but we tested it with spending :robux:1 and it still didn’t award the coins.

Quick question, since a similar thing happened to me in the past. Is this the only script that uses ProcessReceipt ? Do a CTRL+SHIFT+F search for that word. It should only appear in one script because only the most recent assignment will go trough and if you have multiple scripts using it, it’s a chance that it won’t even trigger in this script.

1 Like

This is definitely the only script using it, plus the function is firing after all.

Since the error is attempt to call a nil value I belive it has to do with actual place where the values are being changed. First of all, try printing the handler in the same place where you printed the others.
Also, I recommend check if leaderstats and Coins exist by doing something like this:

productFunctions[1130552603] = function(receipt, player)
    if player:FindFirstChild("leaderstats") then
           print("leaderstats exists")
           if player.leaderstats:FindFirstChild("Coins") then
               print("Coins exists")
	           player.leaderstats.Coins.Value = player.leaderstats.Coins.Value + 50
	           return true
           end
    end
end
1 Like

leaderstats and Coins definitely exist but I will try printing handler.

Handler was nil and I had to fix it by doing a k, v pairs loop. Thanks!