I am attempting to make a stage selector for my dco, but it isn’t working. The buttons “Forward” and “Back” are meant to make me teleport to the next stage, or previous stage (only if you have already beaten that stage). The buttons “vForward” and “vBack” are meant to teleport me 10 stages forward, or 10 stages backward (only if you have already beaten those stages). The buttons “Forward” and “Back” are just teleporting me to random stages, though. The button “vForward” always teleports me to the max stages i’ve reached, and the button “vBack” always teleports me to stage 0.
Here is my code:
local st = script.Parent
local plr = game.Players.LocalPlayer
local cp = workspace.Checkpoints
plr:WaitForChild("TeleportedStage")
repeat task.wait() until plr.leaderstats.Stage.Value ~= 0
plr.TeleportedStage.Value = plr.leaderstats.Stage.Value
while task.wait() do
st.CurrentStage.Text = tostring(plr.TeleportedStage.Value)
st.Back.MouseButton1Down:Connect(function()
if plr.TeleportedStage.Value == 0 then
plr.TeleportedStage.Value = plr.leaderstats.Stage.Value
plr.Character.HumanoidRootPart.CFrame = CFrame.new(cp[plr.leaderstats.Stage.Value].Position)
else
plr.TeleportedStage.Value -= 1
plr.Character.HumanoidRootPart.CFrame = CFrame.new(cp[plr.TeleportedStage.Value].Position)
end
end)
st.vBack.MouseButton1Down:Connect(function()
if plr.TeleportedStage.Value < 10 then
plr.TeleportedStage.Value = 0
plr.Character.HumanoidRootPart.CFrame = CFrame.new(cp["0"].Position)
else
plr.TeleportedStage.Value -= 10
plr.Character.HumanoidRootPart.CFrame = CFrame.new(cp[plr.TeleportedStage.Value].Position)
end
end)
st.Forward.MouseButton1Down:Connect(function()
if plr.TeleportedStage.Value == plr.leaderstats.Stage.Value then
plr.TeleportedStage.Value = 0
plr.Character.HumanoidRootPart.CFrame = CFrame.new(cp["0"].Position)
else
plr.TeleportedStage.Value += 1
plr.Character.HumanoidRootPart.CFrame = CFrame.new(cp[plr.TeleportedStage.Value].Position)
end
end)
st.vForward.MouseButton1Down:Connect(function()
plr.TeleportedStage.Value += 10
if plr.TeleportedStage.Value > plr.leaderstats.Stage.Value then
plr.TeleportedStage.Value = plr.leaderstats.Stage.Value
plr.Character.HumanoidRootPart.CFrame = CFrame.new(cp[plr.leaderstats.Stage.Value].Position)
else
plr.Character.HumanoidRootPart.CFrame = CFrame.new(cp[plr.TeleportedStage.Value].Position)
end
end)
end