Need Help - Dev Product gives inconsistent amount of currency

When I test-buy a developer product I made, each time I buy it, the rewards presented by it double.

My code works this way:

  • LocalScript determines that player wants to purchase product; uses RemoteEvent to send message and Developer Product ID to a script in ServerScriptService
  • Server Script in ServerScriptService prompts purchase to player
  • If purchase is successful, 25 Gold is rewarded to player

That’s at least what it ideally should be. What I mean by the rewards doubling is that when I purchase it for the first time, it rewards me with 25 Gold. If I try to purchase it a second time, it rewards me with 50. Then, it adds 75 more when I buy for the 3rd time. That sequence continues every time I try playing, so my Gold stats go from 0 -> 25 -> 75 -> 150.

The reason I put it in Scripting Support instead of a Bug section is because I think I’m doing something wrong on my end; that’s what the case usually is. Anyways, back to the description.

This is the code in my LocalScript:

local AddGold = game.ReplicatedStorage.DevProduct_AddGold
local devProductID = script.Parent.Parent.DevProductID

script.Parent.Activated:Connect(function(player)
    AddGold:FireServer(devProductID.Value)
end)

Here is the code in the Script in ServerScriptService:

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
game.ReplicatedStorage.DevProduct_AddGold.OnServerEvent:Connect(function(player, devProductID)
	MarketplaceService:PromptProductPurchase(player, devProductID)
		
	local leaderstats = player.leaderstats
	local gold = leaderstats.Gold
	
	MarketplaceService.PromptProductPurchaseFinished:Connect(function(userId, productId, isPurchased)
		if isPurchased then
			if productId == 998890745 then
				gold.Value = gold.Value + 25
			end
		end
	end)
end)
1 Like

This is a common problem. Roblox wants to know if the purchase was successful, if it’s not told it’s successful, it believes it failed and will reward that the next time they pay again. So, to tell Roblox that the purchase was successful, all you have to do is this. Here’s some links to reference. ProcessReceipt and ProductPurchaseDecision.

local function processReceipt(receipt)
    --do stuff
    return Enum.ProductPurchaseDecision.PurchaseGranted
end

marketPlaceService.ProcessReceipt:Connect(processReceipt) --The "Receipt" after a player buys a product
1 Like

Ohhhhh thank you so much! I knew I was forgetting something. :smiley:

By the way, do not use PromptProductPurchaseFinished for handling dev product purchases. It’s not supposed to be used that way and is deprecated for that reason.

Also, ProcessReceipt is a callback, not an event. By using ProcessReceipt, you’re defining what that callback function is. This means you don’t :Connect to anything, you just simply set MarketplaceService.ProcessReceipt = yourFunction

2 Likes

My bad! Thank you for correcting me.

2 Likes