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)
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
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
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.
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
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