My Skip-Stage Script wont work(Fixed!)

Hello, i am working on a obby, i finished it and want to make a skip stage with it and i am trying to figure out why it isnt working.

skip stage starts at the --skip stage

Script:

local marketplaceservice = game:GetService(“MarketplaceService”)

marketplaceservice.ProcessReceipt =function(purchaseInfo)
local plr = game:GetService(“Players”):GetPlayerByUserId(purchaseInfo.PlayerId)
if purchaseInfo.ProductId == 684859645 then – skip to end
– Add the event that will happen when you purchase the dev product.
plr.character.Torso.CFrame = CFrame.new(-2, 5.1, -13.1) – checkpoint 1, spawn
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 5.1, -85.4) – checkpoint 2
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 5.1, -148) – checkpoint 3
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 5.1, -204.8) – checkpoint 4
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 5.1, -270.6) – checkpoint 5
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 5.1, -368.4) – checkpoint 6
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 5.1, -399.4) – checkpoint 7
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 5.1, -474.2) – checkpoint 8
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 5.1, -523) – checkpoint 9
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 5.1, -564.999) – checkpoint 10
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 5.1, -619.799) – checkpoint 11
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 5.1, -648.799) – checkpoint 12
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 5.1, -697.799) – checkpoint 13
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 5.1, -773.798) – checkpoint 14
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 5.1, -832.598) – checkpoint 15
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 5.1, -883.398) – checkpoint 16
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 5.1, -921.397) – checkpoint 17
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 180.3, -925.798) – checkpoint 18
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 180.3, -986.397) – checkpoint 19
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 180.3, -1054.596) – checkpoint 20
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 180.3, -1083.797) – checkpoint 21
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 180.3, -1126.598) – checkpoint 22
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 204.7, -1150.798) – checkpoint 23
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 228.7, -1201.198) – checkpoint 24
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 263.7, -1224.198) – checkpoint 25
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 263.7, -1313.198) – checkpoint 26
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 236.7, -1362.399) – checkpoint 27
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 236.7, -1404.398) – checkpoint 28
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 251.9, -1422.598) – checkpoint 29
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 125.5, -1590) – checkpoint 30
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 125.5, -1641.6) – checkpoint 31
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 125.5, -1674.801) – checkpoint 32
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 125.5, -1787.002) – checkpoint 33
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 87.1, -1834.602) – checkpoint 34
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 87.1, -1885.402) – checkpoint 35
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 87.1, -1944.404) – checkpoint 36
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 87.1, -2007.805) – checkpoint 37
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 87.1, -2059.807) – checkpoint 38
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 87.1, -2116.208) – checkpoint 39
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 87.1, -2167.41) – checkpoint 40
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 87.1, -2218.21) – checkpoint 41
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 87.1, -2285.611) – checkpoint 42
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 87.1, -2338.012) – checkpoint 43
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 87.1, -2396.412) – checkpoint 44
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 87.1, -2457.213) – checkpoint 45
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 87.1, -2518.413) – checkpoint 46
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 122.5, -2592.012) – checkpoint 47
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 122.5, -2644.414) – checkpoint 48
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 122.5, -2741.815) – checkpoint 49
wait(.3)
plr.character.Torso.CFrame = CFrame.new(-2, 122.5, -2830.016) – checkpoint 50
wait(.3)

elseif purchaseInfo.ProductId == 684855556 then – skip stage
if plr.leaderstats.Level == 1 then
plr.character.Torso.CFrame = CFrame.new(-2, 5.1, -85.4)

end
end
end

also no error.

thanks
(also if you need extra details just say so)

update:
It works now, thanks to everyone who helped!

4 Likes

Who wrote that code because it’s wonderful :)))
One of the reasons your ‘skip stage’ does not skip the stage for levels > 1 is that it works only for level 1 as stated in the condition

if plr.leaderstats.Level == 1 then
2 Likes

There is no event that is attached to the product being purchased. And can you please put your code in a code block the next time you post.

Also, this code is very messy and could be easily optimized by having a folder with all the spawns numbered so you don’t have to store all the CFrame values and then using Humanoid:MoveTo you can teleport the players instead of using CFrame.

1 Like

This code is extremely messy. I recommend firing the server with the DevProduct ID, and then there is a module with the DevProduct IDs and what stage it skips it to ( to prevent being exploitable ) , you then prompt the purchase and if the receipt shows the UserId is the same as the one who fired, it checks the module and it sets their position to that stage. This would be much easier than what you currently have.

1 Like

I mocked up some code on my phone real quick to try to steer you in the right direction.

ObbyStages would be a folder with parts with number names that would serve as the spawns instead of a giant table like you have in the original script.

local marketplaceservice = game:GetService(“MarketplaceService”)

marketplaceservice.ProcessReceipt =function(purchaseInfo)
    local plr = game:GetService(“Players”):GetPlayerByUserId(purchaseInfo.PlayerId)
    if purchaseInfo.ProductId == 684859645 then 
        for i,v in pairs(ObbyStages) do
            if v.Name == tostring(plr.leaderstats.Level.Value + 1) then
            plr.Character.Humanoid:MoveTo(v.Position)
            plr.leaderstats.Level.Value = plr.Leaderstats.Level.Value + 1
        end
    end
end
2 Likes

So first, let’s place all this CFrame data into a dictionary of levels to CFrames:

local LevelLocations = {
 -- [level / checkpoint] = CFrame
	[1] = CFrame.new(-2, 5.1, -13.1),
	[2] = CFrame.new(-2, 5.1, -85.4),
	[3] = CFrame.new(-2, 5.1, -148),
	[4] = CFrame.new(-2, 5.1, -204.8),
	[5] = CFrame.new(-2, 5.1, -270.6),
	[6] = CFrame.new(-2, 5.1, -368.4),
	[7] = CFrame.new(-2, 5.1, -399.4),
	[8] = CFrame.new(-2, 5.1, -474.2),
	[9] = CFrame.new(-2, 5.1, -523),
	[10] = CFrame.new(-2, 5.1, -564.999),
	[11] = CFrame.new(-2, 5.1, -619.799),
	[12] = CFrame.new(-2, 5.1, -648.799),
	[13] = CFrame.new(-2, 5.1, -697.799),
	[14] = CFrame.new(-2, 5.1, -773.798),
	[15] = CFrame.new(-2, 5.1, -832.598),
	[16] = CFrame.new(-2, 5.1, -883.398),
	[17] = CFrame.new(-2, 5.1, -921.397),
	[18] = CFrame.new(-2, 180.3, -925.798),
	[19] = CFrame.new(-2, 180.3, -986.397)
	[20] = CFrame.new(-2, 180.3, -1054.596)
	[21] = CFrame.new(-2, 180.3, -1083.797)
	[22] = CFrame.new(-2, 180.3, -1126.598)
	[23] = CFrame.new(-2, 204.7, -1150.798)
	[24] = CFrame.new(-2, 228.7, -1201.198)
	[25] = CFrame.new(-2, 263.7, -1224.198)
	[26] = CFrame.new(-2, 263.7, -1313.198)
	[27] = CFrame.new(-2, 236.7, -1362.399)
	[28] = CFrame.new(-2, 236.7, -1404.398)
	[29] = CFrame.new(-2, 251.9, -1422.598)
	[30] = CFrame.new(-2, 125.5, -1590)
	[31] = CFrame.new(-2, 125.5, -1641.6)
	[32] = CFrame.new(-2, 125.5, -1674.801)
	[33] = CFrame.new(-2, 125.5, -1787.002)
	[34] = CFrame.new(-2, 87.1, -1834.602)
	[35] = CFrame.new(-2, 87.1, -1885.402)
	[36] = CFrame.new(-2, 87.1, -1944.404)
	[37] = CFrame.new(-2, 87.1, -2007.805)
	[38] = CFrame.new(-2, 87.1, -2059.807)
	[39] = CFrame.new(-2, 87.1, -2116.208)
	[40] = CFrame.new(-2, 87.1, -2167.41)
	[41] = CFrame.new(-2, 87.1, -2218.21)
	[42] = CFrame.new(-2, 87.1, -2285.611)
	[43] = CFrame.new(-2, 87.1, -2338.012)
	[44] = CFrame.new(-2, 87.1, -2396.412)
	[45] = CFrame.new(-2, 87.1, -2457.213)
	[46] = CFrame.new(-2, 87.1, -2518.413)
	[47] = CFrame.new(-2, 122.5, -2592.012)
	[48] = CFrame.new(-2, 122.5, -2644.414)
	[49] = CFrame.new(-2, 122.5, -2741.815)
	[50] = CFrame.new(-2, 122.5, -2830.016)
}

Once you put all your data in a data structure, it makes execution of both these gamepass actions very simple:

-- Services
local marketplaceservice = game:GetService("MarketplaceService")
local players = game:GetService("Players")

-- start defining callback for ProcessReceipt
function marketplaceservice.ProcessReceipt(purchaseInfo)
	local plr = players:GetPlayerByUserId(purchaseInfo.PlayerId)
	local lvl = plr.leaderstats.Level

	local HRP = plr.Character and plr.Character:FindFirstChild("HumanoidRootPart") or nil

	if not HRP then -- if HRP doesn't exist, stop early
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end

	if purchaseInfo.ProductId == 684859645 then -- skip to end
		-- use a for loop to loop through all locations, starting at the current level
		for i = lvl.Value, #LevelLocations do
			HRP.CFrame = LevelLocations[i]
			wait(.3)
		end
		lvl.Value = #LevelLocations

		-- purchase now processed
		return Enum.ProductPurchaseDecision.PurchaseGranted
	elseif purchaseInfo.ProductId == 684855556 then -- skip stage

		-- check to see if player is already at the end
		if lvl.Value < #LevelLocations then
			-- increment level by 1 and teleport to respective location
			lvl.Value += 1
			HRP.CFrame = LevelLocations[lvl.Value]

			-- purchase now processed
			return Enum.ProductPurchaseDecision.PurchaseGranted
		else -- player is already at the end
			return Enum.ProductPurchaseDecision.NotProcessedYet
		end
	else -- product id wasn't recognized
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
end)
5 Likes

Do you think something like this work in a model with all of the different checkpoints? just because i have all of them in a model and don’t know if they need to be in a folder.

1 Like

Yes, as long as they are children it will work.

2 Likes