Issue with procces reciept

Hi for some reason every time I use this function it works but sometimes just gives the wrong amount of money. The prompts are right I have no clue why its doing this. I also entered the correct dev product id’s. Anyone know why?

local db = false
game:GetService("MarketplaceService").ProcessReceipt = function(recieptinfo)
	print("yay!")
	if db == false then
		db = true
		local player = script.Parent.Parent.Parent.Parent
		print(recieptinfo.ProductId)
		if recieptinfo.PlayerId == player.UserId and recieptinfo.ProductId == 1624470434 then
			print("paid")
			script.Parent.GameSpin:FireAllClients()
		elseif recieptinfo.PlayerId == player.UserId and recieptinfo.ProductId == 1635739723 then
			player.leaderstats.Cash.Value += 50000
			print("YAHGAH 1")
			player.PlayerGui.MoneyShop.RemoteEvent:FireAllClients()
		elseif recieptinfo.PlayerId == player.UserId and recieptinfo.ProductId == 1635930545 then
			player.leaderstats.Cash.Value += 200000
			print("YAHGAH 2")
			player.PlayerGui.MoneyShop.RemoteEvent:FireAllClients()
		elseif recieptinfo.PlayerId == player.UserId and recieptinfo.ProductId == 1635962585 then
			print("YAHGAH 3")
			player.leaderstats.Cash.Value += 500000
			player.PlayerGui.MoneyShop.RemoteEvent:FireAllClients()
		end
		wait(1)
		db = false
	end

end

This is not how you should use .ProcessReciept. I recommend following Roblox’s example.

Code:

--//Services
local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")

--//Tables
local productFunctions = {}

productFunctions[1624470434] = function(player)
	script.Parent.GameSpin:FireAllClients()
	
	return true
end

productFunctions[1635739723] = function(player)
	player.leaderstats.Cash.Value += 50000
	player.PlayerGui.MoneyShop.RemoteEvent:FireAllClients()
	
	return true
end

productFunctions[1635930545] = function(player)
	player.leaderstats.Cash.Value += 200000
	player.PlayerGui.MoneyShop.RemoteEvent:FireAllClients()

	return true
end

productFunctions[1635962585] = function(player)
	player.leaderstats.Cash.Value += 500000
	player.PlayerGui.MoneyShop.RemoteEvent:FireAllClients()

	return true
end

--//Functions
local function processReceipt(receiptInfo)
	local userId = receiptInfo.PlayerId
	local productId = receiptInfo.ProductId

	local player = Players:GetPlayerByUserId(userId)
	if player then
		-- Get the handler function associated with the developer product ID and attempt to run it
		local handler = productFunctions[productId]
		local success, result = pcall(handler, player)
		if success then
			-- The user has received their benefits!
			-- return PurchaseGranted to confirm the transaction.
			return Enum.ProductPurchaseDecision.PurchaseGranted
		else
			warn("Failed to process receipt:", receiptInfo, result)
		end
	end

	-- the user's benefits couldn't be awarded.
	-- return NotProcessedYet to try again next time the user joins.
	return Enum.ProductPurchaseDecision.NotProcessedYet
end

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

Oh my god thank you so much! It finally worked! After so much time trying to figure it out thank you!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.