Skip Stage Product

Hello! I am trying to make a skip stage product and have looked up different guides online. Thing is mine is structured using teams, and checkpoints. Each checkpoint is called “Stage _” and so on. I have no clue how I would change teams/checkpoints with a skip button. So far for my GUI code I have

local marketPlaceService = game:GetService(“MarketplaceService”)

marketPlaceService.ProcessReceipt = function(receiptInfo)
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)

if receiptInfo.ProductId == 1228407482 then

Any help would be appreciated.

you can change teams using brick colors. I’m not sure if you can get the team name at the player so you can use

for _, i in pairs(game.Teams:GetChildren()) do
if i.BrickColor = player.BrickColor then -- You got the team name
local Stage = tonumber(string.gsub(i.Name, "%D", "")) -- Gets the number only
Stage = Stage + 1
local StageName = tostring(string.gsub(i.Name, "%A", ""))
if game.Teams:FindFirstChild(StageName..Stage) then -- Detects if the next obby exist
local NewTeamColor = game.Teams:FindFirstChild(StageName..Stage).BrickColor
player.BrickColor = NewTeamColor -- I put just player because i don't know what array your trying to do to get the player
end
end
end

reference:
Get all numbers from string
gsub character classes

You could also teleport a player to a spawn point and it will auto-assign it if that is enabled.

local marketPlaceService = game:GetService("MarketplaceService")

marketPlaceService.ProcessReceipt = function(receiptInfo)
	local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
	if receiptInfo.ProductId == 1228407482 then
		local currTeam = player.Team.Name
		currTeam = string.gsub(currTeam, "Stage_", "")
		local nextTeam = tonumber(currTeam) + 1
		nextTeam = game.Teams:FindFirstChild("Stage_"..nextTeam)
		player.Team = nextTeam
		player:LoadCharacter()
	end
end
1 Like

https://developer.roblox.com/en-us/api-reference/property/Player/TeamColor

It’s often a better idea to set Player.Team to the respective Team instead of using this property. Setting this property often leads to repetition of the same BrickColor value for a certain teams across many scripts; this is something you want to avoid when adhering to the don’t-repeat-yourself principle.

1 Like

Got an error saying ServerScriptService, SkipStage8:Attempt to perform arithmetic (add) on nil and number.

Can you share a screenshot of how the teams are named?

Is it formatted like “Stage_One” or “Stage_1” or something else entirely?

1 Like

image

Do I need to add the _ in between each one?

local marketPlaceService = game:GetService("MarketplaceService")

marketPlaceService.ProcessReceipt = function(receiptInfo)
	local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
	if receiptInfo.ProductId == 1228407482 then
		local currTeam = player.Team.Name
		currTeam = string.gsub(currTeam, "Stage ", "")
		local nextTeam = tonumber(currTeam) + 1
		nextTeam = game.Teams:FindFirstChild("Stage "..nextTeam)
		player.Team = nextTeam
		player:LoadCharacter()
	end
end

Should just be a " " instead of a “_”.

1 Like

Thank you so much, I have been trying to figure this out for a while now and thanks to you it is completed! I appreciate your help a ton.

One thing I noticed, so when you first buy the first couple times it moves you up 1 stage, but at one point it duplicates and moves you up 2, then 3, and so on.

local marketPlaceService = game:GetService("MarketplaceService")

marketPlaceService.ProcessReceipt = function(receiptInfo)
	local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
	if receiptInfo.ProductId == 1228407482 then
		if player then
			local currTeam = player.Team.Name
			currTeam = string.gsub(currTeam, "Stage ", "")
			local nextTeam = tonumber(currTeam) + 1
			nextTeam = game.Teams:FindFirstChild("Stage "..nextTeam)
			player.Team = nextTeam
			player:LoadCharacter()
			return Enum.ProductPurchaseDecision.PurchaseGranted
		else
			return Enum.ProductPurchaseDecision.NotProcessedYet
		end
	end
end
1 Like