Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i fix this dev products problem?

So basically its supposed to give you 500 when you purchase it but for some reason it gives you more than that. I think it gives it to you more than once. How do I fix this?

local player =script.Parent.Parent.Parent.Parent.Parent
local MarketplaceService = game:GetService("MarketplaceService")
local buyButton = script.Parent
local productId = 24735683
 
buyButton.MouseButton1Click:connect(function()
	MarketplaceService:PromptProductPurchase(player, productId)
end)

MarketplaceService.ProcessReceipt = function(receiptInfo) 

	for i, player in ipairs(game.Players:GetChildren()) do
		if player.userId == receiptInfo.PlayerId then
					
			if receiptInfo.ProductId == productId then
				
			player.PlayerGui.Money.MonV.Value = player.PlayerGui.Money.MonV.Value + 500
			
			end
		end
	end	
	
	return Enum.ProductPurchaseDecision.PurchaseGranted		
end

1 answer

✓ Accepted answer

I was going to make a comment on this, then I saw way to many incorrect things. First, handling the purchase and the purchasing prompt MUST be in two different things. In the player: (any storage, PlayerGui, StarterPack, works. But if this is for a gui in a player, must be in the gui, in the PlayerGui for effiency.) simple, in a local script, is where you prompt the purchase.

local buyButton = script.Parent
local productId = 24735683
local player = game.Players.LocalPlayer -- script.Parent.Parent.Parent etc. is just so inefficient.
local MarketplaceService = game:GetService("MarketplaceService")

buyButton.MouseButton1Click:connect(function()
    MarketplaceService:PromptProductPurchase(player, productId)
end)

Next, this is where you handle the purchase, if it was made. No need for iteration.

local productId = 24735683
local MarketplaceService = game:GetService("MarketplaceService")

MarketplaceService.ProcessReceipt = function(receiptInfo) 
player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
        if player.userId == receiptInfo.PlayerId then
	 if receiptInfo.ProductId == productId then
	player.PlayerGui.Money.MonV.Value = player.PlayerGui.Money.MonV.Value + 500
            end
        end
    end 

    return Enum.ProductPurchaseDecision.PurchaseGranted     
end

You could also save it using DataStores, but thats not what you asked for, so i wont go there. You were very close, your program was just jumbled and all in one. You cannot handle both purchase and prompt in one. It just doesn't work right, personally, and then the efficency errors. But you main problem was the "for" loop I believe.

This discussion is preserved as it was. New answers, comments, and votes are closed.