I want to make a checkpoint automated Checkpoint system, where once the player touches the checkpoint it will give them the current level. In addition to this, there’s also a red zone where if touched brings the player to their current level’s spawn (so this has to have an automated system as well). I tried using a for loop, but It didn’t seem logic to me. Any way on how to make it?
local redZone = workspace.Gameplay.MapLevel1:WaitForChild("Red zone")
local debounce = false
local checkpointArray = {
game.Workspace.Gameplay.Checkpoints_Spawn.checkpoint2ndLVL;
game.Workspace.Gameplay.Checkpoints_Spawn.checkpoint3rdLVL;
}
local spawnpoint = {
game.Workspace.Gameplay.Checkpoints_Spawn:WaitForChild("firstSpawn");
game.Workspace.Gameplay.Checkpoints_Spawn:WaitForChild("secondSpawn");
game.Workspace.Gameplay.Checkpoints_Spawn:WaitForChild("thirdSpawn");
}
local function firstCheckpoint ()
if checkpointArray then
checkpointArray[1].Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local char = player.Character
local humanoid = char:FindFirstChild("Humanoid")
local currentLvl = player:WaitForChild("leaderstats").Level
if not debounce and currentLvl.Value<3 then
if humanoid then
currentLvl.Value = 2
print("Checkpoint")
debounce = true
task.wait(3)
debounce = false
end
end
end)
end
end
firstCheckpoint()
local function secondCheckpoint()
if checkpointArray then
checkpointArray[2].Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
local char = player.Character
local humanoid = char:FindFirstChild("Humanoid")
local currentLvl = player:WaitForChild("leaderstats").Level
if not debounce and currentLvl.Value<4 then
if humanoid then
currentLvl.Value = 3
print("Checkpoint")
debounce = true
task.wait(3)
debounce = false
end
end
end)
end
end
secondCheckpoint()
-- same thing for the 3rd
if redZone then
redZone.Touched:Connect(function(hit)
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
local character = Player.Character
local humanoid = character:FindFirstChild("Humanoid")
local currentLvl = Player:WaitForChild("leaderstats").Level
local currentSpawnPoint = currentLvl
if humanoid and currentLvl.Value == 1 then
character:SetPrimaryPartCFrame(CFrame.new(spawnpoint[1].Position + Vector3.new(0,5,0)))
print("Checkpoint1")
else if currentLvl.Value == 2 then
print("Checkpoint2")
character:SetPrimaryPartCFrame(CFrame.new(spawnpoint[2].Position + Vector3.new(0,5,0)))
end
if currentLvl.Value == 3 then
print("Checkpoint3")
character:SetPrimaryPartCFrame(CFrame.new(spawnpoint[3].Position + Vector3.new(0,5,0)))
end
end
end)
end