Devproducts work in studio but not in the real game

Hello, developers.

My dev-product script only works in studio. I have no clue why and this shouldn’t happen.
I have no errors aswell.

Code:

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

Marketplace.ProcessReceipt = function(ReceiptInfo)
	local ProductId = ReceiptInfo.ProductId
	local PlayerId = ReceiptInfo.PlayerId
	local Player = Players:GetPlayerByUserId(PlayerId)

	if Player then
		if ProductId == 1259816121 then
			local Points = 100

			Player.leaderstats.Money.Value += Points
			ReplicatedStorage:FindFirstChild("PlaySound"):FireClient(Player, game.Workspace.BoughtSFX)
			ReplicatedStorage:FindFirstChild("SendNotification"):FireClient(Player, "Money Purchased", "You purchased $"..Points.."! Thank you for purchasing", 5)
		elseif ProductId == 1259816120 then
			local Points = 500

			Player.leaderstats.Money.Value += Points
			ReplicatedStorage:FindFirstChild("PlaySound"):FireClient(Player, game.Workspace.BoughtSFX)
			ReplicatedStorage:FindFirstChild("SendNotification"):FireClient(Player, "Money Purchased", "You purchased $"..Points.."! Thank you for purchasing", 5)
		elseif ProductId == 1259816390 then
			local Points = 1000

			Player.leaderstats.Money.Value += Points
			ReplicatedStorage:FindFirstChild("PlaySound"):FireClient(Player, game.Workspace.BoughtSFX)
			ReplicatedStorage:FindFirstChild("SendNotification"):FireClient(Player, "Money Purchased", "You purchased $"..Points.."! Thank you for purchasing", 5)
		elseif ProductId == 1259816391 then
			local Points = 2500

			Player.leaderstats.Money.Value += Points
			ReplicatedStorage:FindFirstChild("PlaySound"):FireClient(Player, game.Workspace.BoughtSFX)
			ReplicatedStorage:FindFirstChild("SendNotification"):FireClient(Player, "Money Purchased", "You purchased $"..Points.."! Thank you for purchasing", 5)
		end
	end

	return Enum.ProductPurchaseDecision.PurchaseGranted
end

Did you try printing to see where it doesn’t run the code?

Yes. It doesn’t print at all, sadly.

Maybe it has to do with the game’s security? Go to game settings - security, what do you have enabled?

Third party teleports and api services.

Maybe add an if statement for if there’s no player

if not player then
	return Enum.ProductPurchaseDecision.NotProcessedYet
end

This will make sure that the player can buy when they are ready

1 Like

write an else statement and print some kind of string to show whether or not that player was loaded.

Edit: Or continue with what @CriticalGorilla said.

So I actually removed this statement while testing and it still doesn’t work.

I tried some new code, however it also doesn’t work.

Code:

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


local function processReceipt(receiptInfo)

	-- Find the player who made the purchase in the server
	local player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
	local Player = player
	if not player then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	
	print(receiptInfo.PlayerId .. " just bought " .. receiptInfo.ProductId)


	if receiptInfo.ProductId == 1259816121 then
		local Points = 100

		Player.leaderstats.Money.Value += Points
		ReplicatedStorage:FindFirstChild("PlaySound"):FireClient(Player, game.Workspace.BoughtSFX)
		ReplicatedStorage:FindFirstChild("SendNotification"):FireClient(Player, "Money Purchased", "You purchased $"..Points.."! Thank you for purchasing", 5)
	elseif receiptInfo.ProductId == 1259816120 then
		local Points = 500

		Player.leaderstats.Money.Value += Points
		ReplicatedStorage:FindFirstChild("PlaySound"):FireClient(Player, game.Workspace.BoughtSFX)
		ReplicatedStorage:FindFirstChild("SendNotification"):FireClient(Player, "Money Purchased", "You purchased $"..Points.."! Thank you for purchasing", 5)
	elseif receiptInfo.ProductId == 1259816390 then
		local Points = 1000

		Player.leaderstats.Money.Value += Points
		ReplicatedStorage:FindFirstChild("PlaySound"):FireClient(Player, game.Workspace.BoughtSFX)
		ReplicatedStorage:FindFirstChild("SendNotification"):FireClient(Player, "Money Purchased", "You purchased $"..Points.."! Thank you for purchasing", 5)
	elseif receiptInfo.ProductId == 1259816391 then
		local Points = 2500

		Player.leaderstats.Money.Value += Points
		ReplicatedStorage:FindFirstChild("PlaySound"):FireClient(Player, game.Workspace.BoughtSFX)
		ReplicatedStorage:FindFirstChild("SendNotification"):FireClient(Player, "Money Purchased", "You purchased $"..Points.."! Thank you for purchasing", 5)
	end


	return Enum.ProductPurchaseDecision.PurchaseGranted
end

MarketplaceService.ProcessReceipt = processReceipt

I’m so confused about this. :confused:
Edit: and yes, the print statement does not print in game.

You removed the if statement for if it’s a player.

1 Like

try this:

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

Marketplace.ProcessReceipt = function(ReceiptInfo)
	local ProductId = ReceiptInfo.ProductId
	local PlayerId = ReceiptInfo.PlayerId
	local Player = Players:GetPlayerByUserId(PlayerId)

	if Player then
		if ProductId == 1259816121 then
			local Points = 100

			Player.leaderstats.Money.Value += Points
			ReplicatedStorage:FindFirstChild("PlaySound"):FireClient(Player, game.Workspace.BoughtSFX)
			ReplicatedStorage:FindFirstChild("SendNotification"):FireClient(Player, "Money Purchased", "You purchased $"..Points.."! Thank you for purchasing", 5)
		elseif ProductId == 1259816120 then
			local Points = 500

			Player.leaderstats.Money.Value += Points
			ReplicatedStorage:FindFirstChild("PlaySound"):FireClient(Player, game.Workspace.BoughtSFX)
			ReplicatedStorage:FindFirstChild("SendNotification"):FireClient(Player, "Money Purchased", "You purchased $"..Points.."! Thank you for purchasing", 5)
		elseif ProductId == 1259816390 then
			local Points = 1000

			Player.leaderstats.Money.Value += Points
			ReplicatedStorage:FindFirstChild("PlaySound"):FireClient(Player, game.Workspace.BoughtSFX)
			ReplicatedStorage:FindFirstChild("SendNotification"):FireClient(Player, "Money Purchased", "You purchased $"..Points.."! Thank you for purchasing", 5)
		elseif ProductId == 1259816391 then
			local Points = 2500

			Player.leaderstats.Money.Value += Points
			ReplicatedStorage:FindFirstChild("PlaySound"):FireClient(Player, game.Workspace.BoughtSFX)
			ReplicatedStorage:FindFirstChild("SendNotification"):FireClient(Player, "Money Purchased", "You purchased $"..Points.."! Thank you for purchasing", 5)
		end

		return Enum.ProductPurchaseDecision.PurchaseGranted

	elseif not Player then
		warn("Player is not ready yet.")
		return Enum.ProductPurchaseDecision.NotProcessedYet

	end


	

end
1 Like

Nothing happened. It didn’t print anything.

it should’ve given a warning.

replace that with print

You can use the code from the MarketplaceService.ProcessReceipt api.

Its the same thing but one is in an orange color.

I’ve already done and tried that, it will not work. :frowning:

You have more than 1 script with devproducts events? If so, consider doing it all in 1.

You cant use devproducts on 2 different scripts, you should handle it in just 1 as i said.

I only have one handler in my game. I will send the product prompt code soon aswell.

1 Like

Code:

local Mark = game:GetService("MarketplaceService")
local Player = game.Players.LocalPlayer

script.Parent.Activated:Connect(function()
	Mark:PromptProductPurchase(Player, script.Parent.Id.Value)
end)

This is in a localscript and it is inside the surface gui in startergui.

This script is all over the place-

You first off should be utilizing the documentation here, which will get you the wanted result. Because this is returning nothing, (true, false, PurchaseGranted, NotProcessedYet, etc…), it won’t work as intended in-studio, nor in-game.

1 Like