So I basically made a checkpoint script, when ever you touch one of the stages then that will be your checkpoint if you meet the requirements, And I also made a gui where you can use 2 buttons to go back, and forth between the stages that you have unlocked, the only issue rn is that when ever you go backwards the touch event prob fires at the same thing causing you to be set back to the stage you just teleported from some times, it is just kind of buggy
I have tried to set a debounce so that the touch event couldn’t continue when the code that is handling the gui stuff is being run, but that also doesn’t seem to work, I just don’t know what the solution could be rn, so if anybody could take the time to help then that would be amazing.
local Collection = game:GetService("CollectionService")
local Rep = game:GetService("ReplicatedStorage")
for _, Stage in pairs(Collection:GetTagged("Stage")) do
Stage.Touched:Connect(function(Hit)
local humanoid = Hit.Parent:FindFirstChild("Humanoid")
if humanoid then
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
local PlayerStage = Player:WaitForChild("leaderstats").Stage
local HSU = Player:WaitForChild("HighestStageUnlocked")
local NewStage = Stage.Name
if PlayerStage.Value > tonumber(NewStage) then
return
end
if PlayerStage.Value ~= tonumber(NewStage) -1 then
return
end
PlayerStage.Value = NewStage
if tonumber(NewStage) > HSU.Value then
HSU.Value = NewStage
end
Rep.Gui:FireClient(Player, NewStage)
end
end)
end
Rep.GuiStageChange.OnServerInvoke = function(_,Player, StageJump)
local leaderstats = Player:WaitForChild("leaderstats")
local Stage = leaderstats:WaitForChild("Stage")
local HSU = Player:WaitForChild("HighestStageUnlocked")
if Stage.Value + StageJump <= HSU.Value then
if Stage.Value + StageJump > 0 then
Stage.Value = Stage.Value + StageJump
local CurrentStage = game.Workspace.Game.Stages:FindFirstChild(Stage.Value)
Player.Character.HumanoidRootPart.CFrame = CurrentStage.CFrame + Vector3.new(0,1,0)
return Stage.Value
end
end
end