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

My value get's doubled when I add it the second time, why is it doing that?

So the first time I buy the skip stage gamepass it adds 1 correctly but when I buy it the second time, then it goes like this: 0 + 1 = 1 1 + 1 = 3 I can't figure out why it's duplicating it. Any help will be appreciated :)

-- Variables
local marketPlaceService = game:GetService("MarketplaceService")
local add = 1

marketPlaceService.ProcessReceipt = function(receiptinfo)
	if receiptinfo.ProductId == 1112744038 then
		local player = game.Players:GetPlayerByUserId(receiptinfo.PlayerId)
		player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 1 
		local hum = player.Character:FindFirstChild("Humanoid")
		if hum then
			hum.Health = 0
		end
	end
end

1 answer

You need to return whether it was purchased or not. I had the same problem before, and I forgot to return the purchase decision, which you've also forgotten as it seems.

-- Variables
local marketPlaceService = game:GetService("MarketplaceService")
local add = 1

marketPlaceService.ProcessReceipt = function(receiptinfo)
    if receiptinfo.ProductId == 1112744038 then
        local player = game.Players:GetPlayerByUserId(receiptinfo.PlayerId)
        player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 1 
        local hum = player.Character:FindFirstChild("Humanoid")
        if hum then
            hum.Health = 0
        end
	return Enum.ProductPurchaseDecision.PurchaseGranted
    end
end

2 comments

0

Your solution helped, thank you!

0

np. also pls make sure to accept the answer whenever its a solution :).

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