Currency Purchases not working!

Hello everyone! I am working on a game which involves coins and I want to make a way to purchase currency. Overall, things had been going pretty well so far, the developer products were being prompted, but all of that came to an end when I started scripting the player receiving their coins. They just don’t get them.

Product Prompts Script (Probably irrelevant)

Product Prompts Script:

local shopframe = script.Parent.Parent
local mps = game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer
local coinshopframe = script.Parent.Parent.Parent.CoinShop
local back = script.Parent.Parent.Parent.Back
coinshopframe.Visible = false

script.Parent.MouseButton1Click:Connect(function()
	shopframe.Visible = false
	coinshopframe.Visible = true
	back.MouseButton1Click:Connect(function()
		shopframe.Visible = false
		coinshopframe.Visible = false
	end)
end)

--DEVPRODUCTS

script.Parent.Parent.Parent.CoinShop["50"].MouseButton1Click:Connect(function()
	mps:PromptProductPurchase(player, 1589020332)
end)

script.Parent.Parent.Parent.CoinShop["100"].MouseButton1Click:Connect(function()
	mps:PromptProductPurchase(player, 1589021131)
end)

script.Parent.Parent.Parent.CoinShop["250"].MouseButton1Click:Connect(function()
	mps:PromptProductPurchase(player, 1589021665)
end)

script.Parent.Parent.Parent.CoinShop["500"].MouseButton1Click:Connect(function()
	mps:PromptProductPurchase(player, 1589022270)
end)

script.Parent.Parent.Parent.CoinShop["1000"].MouseButton1Click:Connect(function()
	mps:PromptProductPurchase(player, 1589023012)
end)

script.Parent.Parent.Parent.CoinShop["5000"].MouseButton1Click:Connect(function()
	mps:PromptProductPurchase(player, 1589023518)
end)

script.Parent.Parent.Parent.CoinShop["10000"].MouseButton1Click:Connect(function()
	mps:PromptProductPurchase(player, 1589025778)
end)

Currency Purchase Handler Script

Currency Purchase Handler Script:

local mps = game:GetService("MarketplaceService")

mps.ProcessReceipt = function(receiptinfo)
	if receiptinfo == 1589020332 then
		local player = game.Players:GetPlayerByUserId(receiptinfo.PlayerId)
		player.leaderstats.Coins.Value += 50
		return Enum.ProductPurchaseDecision.PurchaseGranted
	else
		if receiptinfo == 1589021131 then
			local player = game.Players:GetPlayerByUserId(receiptinfo.PlayerId)
			player.leaderstats.Coins.Value += 100
			return Enum.ProductPurchaseDecision.PurchaseGranted
		else
			if receiptinfo == 1589021665 then
				local player = game.Players:GetPlayerByUserId(receiptinfo.PlayerId)
				player.leaderstats.Coins.Value += 250
				return Enum.ProductPurchaseDecision.PurchaseGranted
			else
				if receiptinfo == 1589022270 then
					local player = game.Players:GetPlayerByUserId(receiptinfo.PlayerId)
					player.leaderstats.Coins.Value += 500
					return Enum.ProductPurchaseDecision.PurchaseGranted
				else
					if receiptinfo == 1589023012 then
						local player = game.Players:GetPlayerByUserId(receiptinfo.PlayerId)
						player.leaderstats.Coins.Value += 1000
						return Enum.ProductPurchaseDecision.PurchaseGranted
					else
						if receiptinfo == 1589023518 then
							local player = game.Players:GetPlayerByUserId(receiptinfo.PlayerId)
							player.leaderstats.Coins.Value += 5000
							return Enum.ProductPurchaseDecision.PurchaseGranted
						else
							if receiptinfo == 1589025778 then
								local player game.Players:GetPlayerByUserId(receiptinfo.PlayerId)
								player.leaderstats.Coins.Value += 10000
								return Enum.ProductPurchaseDecision.PurchaseGranted
							end
						end
					end
				end
			end
		end
	end
end

I don’t see any errors in output. I have tried in the real game and on studio. Thanks to anyone who can possibly help me! :slight_smile:

ProcessReceipt’s receiptinfo is actually a table! You probably want to be using receiptinfo.ProductId Another thing you can do is elseif to reduce your indentation and end statements.

The receiptInfo table passed to this callback will contain the following data:

  • PurchaseId — A unique identifier for the specific purchase.

  • PlayerId — The user ID of the player who made the purchase.

  • ProductId — The ID of the purchased product.

  • PlaceIdWherePurchased — The place ID in which the purchase was made; not necessarily the same as the current place’s ID.

  • CurrencySpent — The amount of currency spent in the transaction.

  • CurrencyType — The type of currency spent in the purchase; always CurrencyType.Robux.

From:

Using elseif

local mps = game:GetService("MarketplaceService")

mps.ProcessReceipt = function(receiptinfo)
	if receiptinfo.ProductId == 1589020332 then
		local player = game.Players:GetPlayerByUserId(receiptinfo.PlayerId)
		player.leaderstats.Coins.Value += 50
		return Enum.ProductPurchaseDecision.PurchaseGranted
	elseif receiptinfo.ProductId == 1589021131 then
		local player = game.Players:GetPlayerByUserId(receiptinfo.PlayerId)
		player.leaderstats.Coins.Value += 100
		return Enum.ProductPurchaseDecision.PurchaseGranted
	elseif receiptinfo.ProductId == 1589021665 then
		local player = game.Players:GetPlayerByUserId(receiptinfo.PlayerId)
		player.leaderstats.Coins.Value += 250
		return Enum.ProductPurchaseDecision.PurchaseGranted
	elseif receiptinfo.ProductId == 1589022270 then
		local player = game.Players:GetPlayerByUserId(receiptinfo.PlayerId)
		player.leaderstats.Coins.Value += 500
		return Enum.ProductPurchaseDecision.PurchaseGranted
	elseif receiptinfo.ProductId == 1589023012 then
		local player = game.Players:GetPlayerByUserId(receiptinfo.PlayerId)
		player.leaderstats.Coins.Value += 1000
		return Enum.ProductPurchaseDecision.PurchaseGranted
	elseif receiptinfo.ProductId == 1589023518 then
		local player = game.Players:GetPlayerByUserId(receiptinfo.PlayerId)
		player.leaderstats.Coins.Value += 5000
		return Enum.ProductPurchaseDecision.PurchaseGranted
	elseif receiptinfo.ProductId == 1589025778 then
		local player = game.Players:GetPlayerByUserId(receiptinfo.PlayerId)
		player.leaderstats.Coins.Value += 10000
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
end

4 Likes

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