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)