Help with developer products

Hello, I am trying to make a script that awards the player with rebirths when they purchase the developer product. For some reason the code is getting stuck at the line “if receiptinfo.PurchaseId == 1597709138”

I have tried to find tutorials and fixes but when I look at them I can seem to figure out what is wrong with it.

Here is the code. Ignore the top half of it since that is just a leaderstat script.

local players = game:GetService('Players')
local marketplace = game:GetService('MarketplaceService')

players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new('Folder', player)
	leaderstats.Name = "leaderstats"
	
	local Stages = Instance.new('IntValue', leaderstats)
	Stages.Name = 'Stage'
	
	local Rebirth = Instance.new('IntValue', leaderstats)
	Rebirth.Name = 'Rebirths'
	
end)

local productid = 1597709138

local function proccessReceipt (receiptInfo)
	
	local player = players:GetPlayerByUserId(receiptInfo.PlayerId)
	if not player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
		
			end
	if receiptInfo.PurchaseId == 1597709138 then
	
		if player then
			print('hello')
			local Rebirths = player.leaderstats.Rebirths
			Rebirths.Value = Rebirths.Value + 1

		end
	end
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

marketplace.ProcessReceipt = proccessReceipt
2 Likes

You are incorrectly using PurchaseId instead of ProductId.

Updated Code:

local players = game:GetService('Players')
local marketplace = game:GetService('MarketplaceService')

players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new('Folder', player)
	leaderstats.Name = "leaderstats"
	
	local Stages = Instance.new('IntValue', leaderstats)
	Stages.Name = 'Stage'
	
	local Rebirth = Instance.new('IntValue', leaderstats)
	Rebirth.Name = 'Rebirths'
	
end)

local productid = 1597709138

local function proccessReceipt (receiptInfo)
	
	local player = players:GetPlayerByUserId(receiptInfo.PlayerId)
	if not player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
		
			end
	if receiptInfo.ProductId == 1597709138 then
	
		if player then
			print('hello')
			local Rebirths = player.leaderstats.Rebirths
			Rebirths.Value = Rebirths.Value + 1

		end
	end
	return Enum.ProductPurchaseDecision.PurchaseGranted
end

marketplace.ProcessReceipt = proccessReceipt

Would like to add on to the previous reply for an explanation:
PurchaseId used in receipts is a unique ID that is used to identify a specific purchase transaction (e.g. You purchase a Devproduct, and the game logs this transaction as the #7284th transaction) , but it does not point to the ID of the product being purchased. Like the previous reply said, ProductId should be the parameter you should check!

ProcessReceipt’s Docs.

3 Likes

you can put it in an other script and add how many products you need

local Products = {
     [1597709138]=function(receipt,player)
		player.leaderstats.Rebirth.Value += 1
     end;
}

function MarketplaceService.ProcessReceipt(receiptinfo)
	local playerProductKey = receiptinfo.PlayerId..":"..receiptinfo.PurchaseId
	local plr = game:GetService("Players"):GetPlayerByUserId(receiptinfo.PlayerId)
	
	local handler
	for ProductId,func in pairs(Products) do
		if ProductId == receiptinfo.ProductId then
			handler = func break
		end
	end
	
local suc = pcall(handler,receiptinfo,plr)
return Enum.ProductPurchaseDecision.PurchaseGranted
end
1 Like