Why does my dev product stack everytime its bought?

why does my dev product stack everytime I buy it

server

game:GetService("MarketplaceService").ProcessReceipt = function(receiptInfo)
    local userId = receiptInfo.PlayerId
    local productId = receiptInfo.ProductId

    local player = game:GetService("Players"):GetPlayerByUserId(userId)

    if not player then
        return Enum.ProductPurchaseDecision.NotProcessedYet
    end

    if receiptInfo.ProductId == 1767636823 then
        game.ReplicatedStorage.BoughtDevProduct:FireClient(player, 1767636823)
        
        return Enum.ProductPurchaseDecision.PurchaseGranted
    end
    
    if receiptInfo.ProductId == 1767786941 then
        game.ReplicatedStorage.BoughtDevProduct:FireClient(player, 1767786941)
        
        return Enum.ProductPurchaseDecision.PurchaseGranted
    end
end

client

marketplaceService:PromptProductPurchase(plr, 1767786941)

game.ReplicatedStorage.BoughtDevProduct.OnClientEvent:Connect(function(ID)
                                print("bought")
                                if ID == 1767786941 then
                                    HatchEgg(result, nearestEgg)
                                    wait(.1)
                                    cooldown = false
                                end
                            end)

“bought” is being printed multiple times

I think there’s something you’re not showing us. Is this client code contained in another function?

it is in a function, all it is is when you press E, if ur near a egg that has an option to open it via pressing E, then it will open it.

	if input.KeyCode == Enum.KeyCode.E then
		if plr.Character ~= nil and isHatching == false then
			local nearestEgg
			local plrPos = plr.Character.HumanoidRootPart.Position

			for i, v in pairs(eggsFold:GetChildren()) do 
				if nearestEgg == nil then
					nearestEgg = v
				else
					if (plrPos - v.PrimaryPart.Position).Magnitude < (nearestEgg.PrimaryPart.Position - plrPos).Magnitude then
						nearestEgg = v
					end
				end
			end		
			if nearestEgg:FindFirstChild("Robuxs") then
				if plr:DistanceFromCharacter(nearestEgg.PrimaryPart.Position) < MaxDisplayDistance then
					canHatch = true
				else
					canHatch = false
				end

				if canHatch == true then
					local result = repStorage:WaitForChild("HatchServer"):InvokeServer(nearestEgg)
					if result ~= "Cannot Hatch" then
						if not cooldown then
							cooldown = true
							marketplaceService:PromptProductPurchase(plr, 1767786941)
							
							game.ReplicatedStorage.BoughtDevProduct.OnClientEvent:Connect(function(ID)
								print("hihihi")
								if ID == 1767786941 then
									HatchEgg(result, nearestEgg)
									wait(.1)
									cooldown = false
								end
							end)
						end
					else
						print("Cannot hatch")
					end
				end
end)```

Okay, I’m not understanding this very well, but have you tried changing this Connect to Once?

i fixed this problem, thank u though

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