Developer Product Issue

Hello, I am still learning scripting and havent worked with developer product set-up or anything like that. I used the documentation kind of as a template to work off of and added my id and thing I would like to happen within it

Local Script (Within a textbutton in a screenggui)

local MarketplaceService = game:GetService("MarketplaceService")
local prodID = 3324799602  -- Make this number your Product ID

script.Parent.MouseButton1Click:Connect(function()
	MarketplaceService:PromptProductPurchase(game.Players.LocalPlayer, prodID)
end)

ServerScript (ServerScriptService)

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

local productFunctions = {}

-- Example: product ID 123123 brings the user back to full health
productFunctions[3324799602] = function(receipt, player)
	local character = player.Character
	local humanoid = character and character:FindFirstChildWhichIsA("Humanoid")

	if humanoid then
		print("Adding part")
		local RainPart = Instance.new("Part")
		RainPart.Name = "RainPart"
		RainPart.Size = Vector3.new(3,1,3)
		RainPart.Anchored = true
		RainPart.Transparency = .4
		RainPart.Parent = workspace
		if workspace:FindFirstChild("RainPart") then
			print("Found RainPart")
		end
		return true
	end
end

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

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

	-- The user's items couldn't be awarded
	-- Returns "NotProcessedYet" and tries again next time the user joins the experience
	return Enum.ProductPurchaseDecision.NotProcessedYet
end

-- Sets the callback
-- This can only be done once by one server-side script
MarketplaceService.ProcessReceipt = processReceipt

I understand you cannot test developer products in studio so i published it to a private game and played, im spending real robux on it, but nothing is happening, none of my prints are firing either, I dont understand whats going on. Would really appreciate some help understanding why this isn’t doing anything.

Seems to work for me?
image

And you can test product purchases in studio by the way

1 Like

From what I read you couldn’t, but I do believe you if you say otherwise. But then I do not understand why I dont even receive a print…

I mean you’re testing in game right? Could it be that 1. you haven’t published? or 2. you’re checking client output and not server output?

It includes all outputs, and ive tested both in game, published, and in studio.

The fact that it worked for me out of the box means that there’s nothing wrong with your code, it’s more your development environment. It could be that your server script isn’t executing for some reason? Try sticking a print statement at the top and see if it fires, do the same for the local script too

1 Like

It seems to work on and off, sometimes purchasing the product does nothing and other times it executes as supposed to, Im going to run a few more time with the prints to see if it has to do with execution.

Ignore that I didnt see output.

Yeah so both scripts fire their prints, but sometimes the purchase does nothing.

I mean I couldn’t make it not fire for me once, it could be another script interfering somehow

The only other script I have thats remotely the same is a prompt for admin, which has a different ID. And HD Admin has its own way of handling purchases so I dont believe it should interfere. The only thing I can think of is that I need to republish as a new place.

I moved to a new test place with the 2 scripts, and it works just fine every time, so it has something to do with the place. And I am not too great at scripting so I cant say for sure if its script interference or just the fact that its not working in that specific experience

like the comment in the server script says, make sure there is only one callback

search every script (ctrl+shift+f)
and see if another script is using ProcessReceipt

if another one is there thats your problem.

1 Like

That would matter across scripts, and not just script specific?

I tried the way you recommended, didnt see it the first time. I do see one for a donation board though. So if I am to only use one, does it matter which one I delete? and if so how I do I make sure the products work each time?

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