A friend and I are currently working on a small obby to test our Lua scripting skills and we're currently working on a checkpoint system that will respawn your character at the latest checkpoint you were at.
I have a part below the obby level that teleports you back to the checkpoint if you fall but when you run into a kill part it teleports you back you level one. I've tried all sorts of ways of trying to fix this error. I've gotten pretty close to almost solving it but can't seem to get any further with it.
This is what I'm using to teleport a player back when they fall and it works like a charm.
-- VARIABLES
local Players = game:GetService("Players")
local fallRespawnPart = workspace.Map.Barriers:FindFirstChild("respawn")
-- IF PLAYER HIT THE RESPAWN BARRIER , TELEPORT THEM 2 STUDS ABOVE THE LAST CHECK POINT
fallRespawnPart.Touched:connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local plr = Players:GetPlayerFromCharacter(hit.Parent)
local respawnPoint = workspace:FindFirstChild("Checkpoints"):FindFirstChild(tostring(plr.leaderstats.Stages.Value))
plr.RespawnLocation = respawnPoint
plr.Character.HumanoidRootPart.Position = respawnPoint.Position + Vector3.new(0, 2, 0)
end
end)
This is how far I got with checking if the player has respawned and if so teleport them back to the checkpoint but it seems to always teleport back to the start of the obby. If you need any more details I'm happy to give it
-- Player Enters Game
Players.PlayerAdded:Connect(function(player)
-- CHECK FOR CHARACTER RESPAWN
player.CharacterAdded:Connect(function(character)
-- GRAB LOCAL PLAYER
local plr = Players:GetPlayerFromCharacter(character)
-- SET MOST RECENT CHECKPOINT FROM LEADERSTATS VALUE
local respawnPoint = workspace:FindFirstChild("Checkpoints"):FindFirstChild(tostring(plr.leaderstats.Stages.Value))
-- SET SPAWN LOCATION
plr.RespawnLocation = respawnPoint
-- RESPAWN HUMANOID AT LOCATION WITH 2 STUDS ABOVE GROUND
plr.Character.HumanoidRootPart.Position = respawnPoint.Position + Vector3.new(0, 2, 0)
end)
end)
Checkpoint Tree:
Workspace --> Checkpoints --> [1, 2, 3, 4] <-- These are the names of my spawnlocations

2 comments
Why are you geting player again when you have the player parameter? Also you do not need to use FindFirstChild recursively
I didnt see it was already answered. Can you put a [SOLVED] in your title so it marks as solved?