Value duplicating (or increasing incorrectly) instead of giving just 100 XP

I made a gamepass that gives the player 100 cash/XP but if they don’t buy it, it gives a warning saying they didn’t.

The warning duplicated (I could’t get the pattern… 1 to 3, then 3-6…HUH) everytime I cancel the gamepass (Video linked below)

ALSO, if I DO buy the gamepass, my value duplicates or increases way more than 100 coins/XP.

Why is this happening?

Video:

Code:

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local gamePassID = 20910551

-- Function to prompt purchase of the game pass
local function promptPurchase(player)
	MarketplaceService:PromptGamePassPurchase(player, gamePassID)

	MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, gamePassID, was_purchased)
		if was_purchased then
			player.leaderstats.XP.Value += 100
		else
			warn(player.Name.." didn't buy the gamepass!")
		end
	end)
end

game.ReplicatedStorage.XPGamePass.OnServerEvent:Connect(function(player)
	promptPurchase(player)
end)

Try this:

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local gamePassID = 20910551

MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, passID, was_purchased)
	if passID == gamePassID then
        if was_purchased then
		    player.leaderstats.XP.Value += 100
	    else
		    warn(player.Name.." didn't buy the gamepass!")
	    end
    end
end)

game.ReplicatedStorage.XPGamePass.OnServerEvent:Connect(function(player)
	MarketplaceService:PromptGamePassPurchase(player, gamePassID)
end)
1 Like