Super weird DevProduct bug

I’m trying to make a developer product that triggers a “coin shower” function in my game. It works fine the first time the player purchases it, but then after that it gets pretty buggy.

If the same player buys it > once, it does the event twice for some reason

No errors, it just repeats the code twice. I’ll show pics.

local player = game.Players.LocalPlayer
local MARKET_PLACE_SERVICE = game:GetService("MarketplaceService")
local PRODUCT_ID = 1540362914

script.Parent.MouseButton1Click:Connect(function()
	
	MARKET_PLACE_SERVICE:PromptProductPurchase(player, PRODUCT_ID)
	
	
end)
-- This works fine, but then in the server script...

You can ignore the last part of the next block I will show.

MARKET_PLACE_SERVICE.ProcessReceipt = function(info)
	
	local id = info.ProductId
	local Player = game.Players:GetPlayerByUserId(info.PlayerId)
	
	if id == productid then
		
		game.ReplicatedStorage["Robux Events"].CoinShower.CoinSgowerReturn:FireAllClients(Player.Name) 
--RIGHT HERE - If the player buys it more than once it runs twice - the remote event 
-- is fired twice, causing two notifications to be sent to the player, and causing double coin shower 
		wait(10)
		
		
		local spawning = 0
		while true do
			if spawning >= 50 then
				break
			end
			wait(.7)
			coin()
			spawning += 1
		end
	end
	script.Enabled = false
	local scriptclone = script:Clone()
	scriptclone.Enabled = true
	scriptclone.Parent = game.ServerScriptService["Robux Purchases"].Storage
	script:Destroy()
end

Any help is appreciated!!!

2 Likes

Do you return Enum.ProductPurchaseDecision.PurchaseGranted? If not, Roblox will continue processing your receipt every single time that player joins your game until you return that Enum.

1 Like

where in the script should I do this?

Inside the ProcessReceipt, when you finish granting the player all required perks, to let Roblox know that the transaction went through successfully.

1 Like

Ok, I tried this, and it works good. But for my coin shower thing, it takes about 50 seconds for everything to happen. And if someone buys a different product in the mean time, what will happen?

Well, you have this wait() call before the shower happens I assume. Try removing it (if that won’t break your code) and see what happens. If someone else buys another (or the same product) a separate thread will be created for this piece of code, it won’t yield as far as I know.

Alright, thank you for your help!

1 Like

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