Detecting gamepass purchase bug

Basically, the first time a player buys a gamepass, it adds the correct amount to the players leaderstats, but the second time it will add the price of the previous gamepass aswell as the current gamepass onto the leaderstat value. Any ideas why?

MarketPlaceService.PromptGamePassPurchaseFinished:Connect(function(loserPlayer, itemId, was_purchased)
				if was_purchased then
					
					local productInfo = MarketPlaceService:GetProductInfo(itemId, Enum.InfoType.GamePass)
					local itemPrice = productInfo.PriceInRobux
					local creator = productInfo.Creator

					loserPlayer.leaderstats.Donated.Value += itemPrice
					local playerId = loserPlayer.UserId
					local itemPriceString = tostring(itemPrice)

					local loserName = loserPlayer.Name
					local Message = "[SYSTEM]: " .. loserName .. " donated " .. itemPriceString .. " ROBUX to " .. creator.Name .. "!"
					local colour = Color3.fromRGB(38, 212, 212)

					donatedChatEvent:FireAllClients(colour, Message)

					-- Check if the winner and loserPlayer exist
					if workspace:FindFirstChild(creator.Name) and workspace:FindFirstChild(loserPlayer.Name) then
						-- Check if the DonationEffect and Purchase sound exist
						if game:GetService("ServerStorage").Effects:FindFirstChild("DonationEffect") and workspace.Sounds:FindFirstChild("Purchase") then
							local purchaseEffect = game:GetService("ServerStorage").Effects.DonationEffect.Attachment:Clone()
							purchaseEffect.Parent = workspace[creator.Name].Head

							local sound = workspace.Sounds.Purchase
							local sound1 = sound:Clone()

							sound1.Parent = workspace:FindFirstChild(loserPlayer.Name).Torso
							sound1:Play()
							sound1.Ended:Once(function()
								sound1:Destroy()
							end)

							task.wait(2.5)

							if purchaseEffect then
								purchaseEffect:Destroy()
							end
						else
							print("DonationEffect or Purchase sound not found in the game.")
						end
					else
						print("Winner or loserPlayer not found in the workspace.")
					end

				else
					return
				end
				return
			end)
1 Like

Your explanation has confused me a little, but this is what I got.

Firstly a gamepass can only be bought once, if you were thinking of something you can buy multiple times (ex. cash) that’s a Developer Product.
Do you mean that the second time it gets bought, it adds the price of the 1st time buying and 2nd time buying? (If its a gamepass, this shouldn’t be possible. Unless Im missing something)

1 Like

From what I’ve seen, there’s no error in this code. The problems are the parameters passed into the functions.

1 Like