Product Purchased running more than once

Hi, developers!

I’m trying to make a 2x chance, but every time the player purchases the item, it seems to not be accurate when dividing. When I purchase the product 2 times, I should be at 250 chance, but… it apparently runs two extra times.

Studio Recording

As seen in my code I’m about to post, I’ve included:

return  Enum.ProductPurchaseDecision.IsSuccessful

to try and stop the issue, but it doesn’t!!

here’s the full code btw!!!:

local button = script.Parent
local asset = 1647885321

button.MouseButton1Click:Connect(function()
	local market = game:GetService('MarketplaceService')
	market:PromptProductPurchase(game.Players.LocalPlayer, asset)
	
	market.PromptProductPurchaseFinished:Connect(function(plrId, assetId, bought)
		if bought == true then
			game.Players.LocalPlayer.leaderstats.Chance.Value /= 2
			print('plr bought asset')
			return Enum.ProductPurchaseDecision.PurchaseGranted
		end
	end)
end)

Any help is hugely appreciated, as I need the game released pretty soon!

It may be because a new PromptProductPurchaseFinished event is connected everytime the button is clicked. Try moving it outside of the button event?

local button = script.Parent
local asset = 1647885321

button.MouseButton1Click:Connect(function()
	local market = game:GetService('MarketplaceService')
	market:PromptProductPurchase(game.Players.LocalPlayer, asset)
end)

market.PromptProductPurchaseFinished:Connect(function(plrId, assetId, bought)
		if bought == true then
			game.Players.LocalPlayer.leaderstats.Chance.Value /= 2
			print('plr bought asset')
			return Enum.ProductPurchaseDecision.PurchaseGranted
		end
	end)
1 Like


Got an error right off the bat. I have no idea how PromptProductPurchaseFinished works, I even read the documentation, so my little hamster wheel of a brain cant figure out a solution.

thats my bad, marketserviceplace wasn’t defined

local button = script.Parent
local asset = 1647885321
local market = game:GetService('MarketplaceService')
button.MouseButton1Click:Connect(function()
	
	market:PromptProductPurchase(game.Players.LocalPlayer, asset)
end)

market.PromptProductPurchaseFinished:Connect(function(plrId, assetId, bought)
	if bought == true then
		game.Players.LocalPlayer.leaderstats.Chance.Value /= 2
		print('plr bought asset')
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
end)
2 Likes

Just make sure to define market outside of the button click.

local market = game:GetService('MarketplaceService')
button.MouseButton1Click:Connect(function()
	market:PromptProductPurchase(game.Players.LocalPlayer, asset)
end)

market.PromptProductPurchaseFinished:Connect(function(plrId, assetId, bought)
		if bought == true then
			game.Players.LocalPlayer.leaderstats.Chance.Value /= 2
			print('plr bought asset')
			return Enum.ProductPurchaseDecision.PurchaseGranted
		end
	end)

edit: nvm they got it first

Worked like a charm. Thanks for the help!

1 Like