I need help with my Script!

I am currently working on an Obby and wanted a Donationboard and a skip stages button but both separately has not worked because of the processreceipt therefore I have both processreceipt scripts programmed into one and now it works BUT there is an annoying nasty bug, there is yes in the script +1 which means that you go 1 stage further but after the 2nd stage you go 2 stages further and after the 3rd stage 3 stages further. And I just do not understand why. And that’s why I need help!

local Products = require(script.Parent.Parent.workspace.Boards.Products)
local Enabled = true

function GetData()
	local Datastore = game:GetService("DataStoreService"):GetDataStore("BoardData")
	local Data = Datastore:GetAsync("Data")
	if Data == nil then
		Data = {ListSize = 15, Datastore = 1, Refresh = 1, Version = 2}
	end

	local TD = "TopDonators"

	if Data.Datastore ~= 1 then
		TD = "TopDonators"..Data.Datastore
	end

	return TD
end

function ReceiptHandler()
	warn("Donation Board: ProcessReceipt Activated")
	game:GetService("MarketplaceService").ProcessReceipt = function(receiptInfo)
		local plr = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
		if receiptInfo.ProductId == 1205369919 then 
			plr.leaderstats.Stage.Value = plr.leaderstats.Stage.Value + 1
			local numbar = plr.leaderstats.Stage.Value
			local stagee = game.Workspace.Stages:WaitForChild(numbar)
			plr.Character:SetPrimaryPartCFrame(CFrame.new(stagee.Position))
			wait(1)
			plr.Character.Humanoid.Health = 0
		end
		local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_product_" .. receiptInfo.ProductId
		local numberBought = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory"):IncrementAsync(playerProductKey, 1)
		local ProductBought = game:GetService("DataStoreService"):GetDataStore("PurchaseHistoryCount"):IncrementAsync(receiptInfo.ProductId, 1)
		local PlayerFound = false
		for i, v in pairs (game.Players:GetChildren()) do
			if v:IsA('Player') then
				if v.userId == receiptInfo.PlayerId then
					for _, p in pairs (Products.Products) do
						if p.ProductId == receiptInfo.ProductId then
							if v ~= nil then
								PlayerFound = true
								game:GetService("DataStoreService"):GetOrderedDataStore(GetData()):IncrementAsync(receiptInfo.PlayerId, p.ProductPrice)
							end
						end
					end
				end
			end
		end
		if PlayerFound ~= true then
			return Enum.ProductPurchaseDecision.NotProcessedYet 
		else
			return Enum.ProductPurchaseDecision.PurchaseGranted		
		end
	end	
end

if Products.AbortCustomPurchases then
	if Products.AbortCustomPurchases == true then
		Enabled = false
		warn("Donation Board: Custom ProcessReceipt Enabled!")
	else
		ReceiptHandler()
	end
else
	ReceiptHandler()
end

Just to clarify, when you skip a stage from stage 1 you only skip 1 stage but when you skip a stage from stage 2 you skip 2 stages?

1 Like

No, if I am in stage 1 and want to skip the stage then I come to stage 2. BUT if I am in stage 2 and then skip then I come to stage 4 and if I skip in stage 4 then I come to stage 7 and if I skip in stage 7 I come to stage 11 and if I skip in stage 11 I come to stage 16 and …

Does the stage value in the leaderboard directly skip from 2 to 4 or does it go 2 to 3 then to 4?

1 Like

it jumps directly from 2 to 4 without 3

if Products.AbortCustomPurchases then
	Enabled = false
	warn("Donation Board: Custom ProcessReceipt Enabled!")
else
	ReceiptHandler()
end

This can replace that last block of code since both are exactly the same.

1 Like

I’m sorry but it did not help would you have another idea plz?

function ReceiptHandler()
	warn("Donation Board: ProcessReceipt Activated")
	game:GetService("MarketplaceService").ProcessReceipt = function(receiptInfo)
		local plr = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
		if receiptInfo.ProductId == 1205369919 then 
			plr.leaderstats.Stage.Value = plr.leaderstats.Stage.Value + 1
			local numbar = plr.leaderstats.Stage.Value
			local stagee = game.Workspace.Stages:WaitForChild(numbar)
			plr.Character:SetPrimaryPartCFrame(CFrame.new(stagee.Position))
			wait(1)
			plr.Character.Humanoid.Health = 0
            return Enum.ProductPurchaseDecision.PurchaseGranted
		end

You needed to add return Enum.ProductPurchaseDecision.PurchaseGranted at the end of the function to signify that the purchased product was granted to the purchaser.

1 Like

That was just an efficiency edit, nothing to do with the actual problem.

1 Like

OMG thank you!!! It’s work!!!