Dev Products not working

Hello, I’m trying to make multiple dev products but currently I’m facing some problems, it looks like the dev products are not giving me money

Server:

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

local DevProducts = {}
local ProductFunctions = {}

function DevProducts.GiveProduct(info)
	
	ProductFunctions[1257918026] = function(receipt, player)
		print("success bought")
		local clicks = player:FindFirstChild("Clicks")
		if clicks then
			clicks.Value += 1000
		end
	end
	
	ProductFunctions[1258414904] = function(receipt, player)
		print("success bought")
		local clicks = player:FindFirstChild("Clicks")
		if clicks then
			clicks.Value += 5000
		end
	end
	
	ProductFunctions[1258443263] = function(receipt, player)
		print("success bought")
		local clicks = player:FindFirstChild("Clicks")
		if clicks then
			clicks.Value += 25000
		end
	end
	
	ProductFunctions[1258443687] = function(receipt, player)
		print("success bought")
		local clicks = player:FindFirstChild("Clicks")
		if clicks then
			clicks.Value += 50000
		end
	end
	
	ProductFunctions[1258443686] = function(receipt, player)
		print("success bought")
		local clicks = player:FindFirstChild("Clicks")
		if clicks then
			clicks.Value += 100000
		end
	end
end

function DevProducts.ProcessReceipt()
	MarketplaceService.ProcessReceipt = function(receiptInfo)
		local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
		local product = receiptInfo.ProductId
		
		if not player then
			-- player could have left the game
			return Enum.ProductPurchaseDecision.NotProcessedYet
		end
		
		local handler
		
		for id, v in pairs(ProductFunctions) do
			if id == receiptInfo.ProductId then
				handler = v
				break
			end
		end
		
		local success, result = pcall(handler,receiptInfo, player)
		--if result then
		--	warn("An error occurred!")
		--	return Enum.ProductPurchaseDecision.NotProcessedYet
		--end
		
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
end

MarketplaceService.ProcessReceipt = DevProducts.ProcessReceipt

return DevProducts

the server. I don’t know what’s going on I just tried to search in some forums and ctrl c and v them, but it doesn’t work.

Client:

local function createProductItem()
	for i, productId in pairs(Products) do
		local productObj = script:WaitForChild("ProductObj"):Clone()
		local product = MarketplaceService:GetProductInfo(productId, Enum.InfoType.Product)
		productObj.Name = product.Name
		productObj.Text = product.Name
		productObj.Parent = productsFrame
		
		productObj.MouseButton1Click:Connect(function()
			print(product.Name)
			MarketplaceService:PromptProductPurchase(player, productId)
		end)
	end
end

createProductItem()

the client just creates the dev products

2 Likes

It would be much better if you create dictionaries with ProductId as the key and set the value to the number of clicks you want to give.

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

local DevProducts = {
	[1257918026] = 1000,
	[1258414904] = 5000,
	[1258443263] = 25000,
	[1258443687] = 50000,
	[1258443686] = 100000
}

local function HandlePurchase(receiptInfo)
	local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
	local productId = receiptInfo.ProductId
	if player and DevProducts[productId] then
		local Clicks = player:FindFirstChild("Clicks")
		if Clicks then
			Clicks.Value += DevProducts[productId]
			return Enum.ProductPurchaseDecision.PurchaseGranted
		end
	else
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
end

MarketplaceService.ProcessReceipt = HandlePurchase
3 Likes