Help with PromptProductPurchaseFinnished

Hey DevFourm, I am trying to make a button prompt a product purchase. When the Purchase is complete. The script checks to see if the player has purchased the product. If they have, the script will add the amount of money according to the product they buy.

Here’s the problem I’m having:
Let’s say I buy the $5,000 money product. It completes it but adds all of the money options together which makes $1,600,000 money. I think when I buy one of the money products, it fires all of the scripts science that all use the same “PromtProductPurchaseFinnished”.

I just need to figure out if there is any way to run the “PromtProductPurchaseFinnished” so it only fires in the one script that prompted.

Here’s a video if the problem:

Here is the button script for all the buttons (This is the one for the $5,000 one):

local MARKET_PLACE = game:GetService("MarketplaceService")
local BUTTON = script.Parent
local PRODUCT = 1802507290
local PLAYERID = game.Players.LocalPlayer.UserId
local MESSAGE = game.Players.LocalPlayer.PlayerGui.MESSAGE.MESSAGE
BUTTON.MouseButton1Click:Connect(function()
	MARKET_PLACE:PromptProductPurchase(game.Players.LocalPlayer, PRODUCT)
end)

MARKET_PLACE.PromptProductPurchaseFinished:Connect(function(PLAYERID, PRODUCT, PURCHASED)
	if PURCHASED then
		game.ReplicatedStorage.STATS.Money.Value += 5000
		MESSAGE.Text = "Thank You For Your Purchase!"
		MESSAGE.TextColor3 = Color3.new(0.333333, 1, 0)
		MESSAGE.Visible = true
	else
		
		return
	end
end)

Thank You :slight_smile:

I’d make handling the PromptProductPurchaseFinished dealt with on the server.

Like this

-- # Services
local Players = game:GetService('Players')
local MarketplaceService = game:GetService('MarketplaceService')
local ReplicatedStorage = game:GetService('ReplicatedStorage')

-- # Stats
local Stats = ReplicatedStorage:WaitForChild('STATS')

-- # Products
local Products = {
    [1802507290] = function(player: Player) --> 5,000
        local MoneyValue = Stats:WaitForChild('Money')

        MoneyValue.Value += 5000
    end;
}

-- # Functions
MarketplaceService.PromptProductPurchaseFinished:Connect(function(userId, productId, isPurchased)
    if not isPurchased then
        return
    end

    local Player = Players:GetPlayerByUserId(userId)
    local ProductFunction = Products[productId]

    if Player == nil then
        return
    end

    if ProductFunction ~= nil then
        ProductFunction(Player)
    end
end)

When I prompt it in a local script, put this into a server script, it still does the same thing even with all other buy button scripts disabled.

Then its probably some other script doing it because with this PromptProductPurchaseFinished it only adds 5000, which is a set value so check ur other scripts and see if you have any other PromptProductPurchaseFinish connections that use the same product ID

When you have multiple PromptProductPurchaseFinished events, the event will fire for every script you have it written. I’m assuming you have PromptProductPurchaseFinished in every button, which is causing it to fire 6 times (once for every button)

What @x6nnx said is right, you need to have it only in a single script and use the productId it returns to check how much money to give

Edit: with products you should also be using ProcessReceipt, not rely on purchasefinished. There’s an example of how to do exactly what you want on the docs page for it