Gems Dev Product not working

Hey so whenever i purchase my dev product for 500 gems, everything works fine, no errors but i just never get the gems. this is my devproduct script, is is on a server script and I think it is only this script as the prompt purchase works fine. Does anyone know how to fix it?

local MarketPlaceService = game:GetService("MarketplaceService")
local players = game.Players

local Dev1kC = 1196082194

local function processReceipt(receiptInfo)
	
	local player = players:GetPlayerByUserId(receiptInfo.PlayerId)
	
	if receiptInfo.ProductId == Dev1kC then
		player.leaderstats.Gems.Value = player.leaderstats.Gems.Value + 500
	end
	
	return Enum.ProductPurchaseDecision.PurchaseGranted
	
end

MarketPlaceService.ProcessReceipt = processReceipt

I am pretty sure your way of doing it is wrong, I don’t work on purchases much, but this should probably work?

local productFunctions = {}


productFunctions[1196082194] = function(receipt, player) -- add the function for 500 gems
	player.leaderstats.Gems.Value = player.leaderstats.Gems.Value + 500
end


local MarketPlaceService = game:GetService("MarketplaceService")
local players = game.Players

local function processReceipt(receiptInfo)
	local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
	
	if not player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	
	local handler = productFunctions[receiptInfo.ProductId]

	local success, result = pcall(handler, receiptInfo, player) -- failed
	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
	
	-- finish, success
	return Enum.ProductPurchaseDecision.PurchaseGranted	
end

MarketPlaceService.ProcessReceipt = processReceipt

(most of the code is from developer.roblox.com) If it doesn’t work please tell me!

Hey thanks for the reply but it comes up with this error Error occurred while processing a product purchase

I will check the script, hold on.

Oh my, so I was double checking the script and I had mistyped the id, I have fixed it and it still doesn’t work in studio but i’m going to test it in a public game

I figured it out,

local productFunctions = {}


productFunctions[1196082194] = function(receipt, player) -- add the function for 500 gems
	player.leaderstats.Gems.Value = player.leaderstats.Gems.Value + 500
        return true
end


local MarketPlaceService = game:GetService("MarketplaceService")
local players = game.Players

local function processReceipt(receiptInfo)
	local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
	
	if not player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	
	local handler = productFunctions[receiptInfo.ProductId]

	local success, result = pcall(handler, receiptInfo, player) -- failed
	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
	
	-- finish, success
	return Enum.ProductPurchaseDecision.PurchaseGranted	
end

MarketPlaceService.ProcessReceipt = processReceipt

It just needed a return statement, hope you enjoy!

yeah mine still doesn’t work but I’ll give your new code a try, thanks

You also may still need to change the id if it’s wrong.

Are there any other scripts managing dev product purchases inside the place? There’s a chance they interfere with each other causing the issue(also the code must execute from a Script).

yeah there aren’t any other scripts, and currently nothing is working :frowning:

Try this:

local MarketPlaceService = game:GetService("MarketplaceService")
local players = game.Players

local Dev1kC = 1196082194

local function processReceipt(receiptInfo)

	local player = players:GetPlayerByUserId(receiptInfo.PlayerId)
	
	if not player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	
	if receiptInfo.ProductId == Dev1kC then
		if player then
			player.leaderstats.Gems.Value = player.leaderstats.Gems.Value + 500
			
			return Enum.ProductPurchaseDecision.PurchaseGranted
		end
	end
end

MarketPlaceService.ProcessReceipt = processReceipt

What is the way the developer product is being prompted?
I made a version of the script that I tested in a server script and it worked flawlessly:


local productFunctions = {}


productFunctions[1233544200] = function(receipt, player) -- add the function for 500 gems
	print("work")
    return true
end


local MarketPlaceService = game:GetService("MarketplaceService")
local players = game.Players

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

	if not player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end

	local handler = productFunctions[receiptInfo.ProductId]

	local success, result = pcall(handler, receiptInfo, player) -- failed
	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

	-- finish, success
	return Enum.ProductPurchaseDecision.PurchaseGranted	
end

MarketPlaceService.ProcessReceipt = processReceipt



local p = game.Players:WaitForChild("forest_walker") -- dont do this

p.Chatted:Connect(function() -- hook it to the chat, normally it would be on a gui or something
	MarketPlaceService:PromptProductPurchase(p, 1233544200)
end)

Yeah thanks this works, I think all of them must’ve worked but I deleted all the other Gem developer product scripts and it seems to work, do i need all of the same products to be in the same script?

Best to put them all in one script, but make sure to manage them correctly.

when you mean manage do you mean just putting each function below each other or is there something i need to follow?

Example(can probably be done in other ways)

local MarketPlaceService = game:GetService("MarketplaceService")
local players = game.Players

local Dev1kC = 1196082194
local Dev2kC = 2392382392 -- random numbers

local function processReceipt(receiptInfo)

	local player = players:GetPlayerByUserId(receiptInfo.PlayerId)
	
	if not player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	
	if receiptInfo.ProductId == Dev1kC then
		if player then
			player.leaderstats.Gems.Value = player.leaderstats.Gems.Value + 500
			
			return Enum.ProductPurchaseDecision.PurchaseGranted
		end
	elseif receiptInfo.ProductId == Dev2kC then
		if player then
			player.leaderstats.Gems.Value = player.leaderstats.Gems.Value + 1000

			return Enum.ProductPurchaseDecision.PurchaseGranted
		end
	end
end

Also, make sure to mark my post as a solution so people know it’s solved :).

okay so it seems that the only way i can do it is with it all being in the same script, if I have more than 1 script even for another dev product it just doesn’t work

yeah nah it doesn’t work with that script, it broke the 500 gems too, so nothing is working again. pretty confusing

yea this code works but as soon as i add player.leaderstats.Gems.Value = player.leaderstats.Gems.Value + 500 then it breaks

What is the error?

charactersarecool