So i wrote a pretty sensible code to make a checkpoint work when it is stepped on. How do i make it so when you die, it will teleport you to the checkpoint? Here is my attempt:
local checkFolder = game.Workspace.checkpoints
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local checkpoints = Instance.new("IntValue")
checkpoints.Name = "Stages"
checkpoints.Parent = leaderstats
for i,v in pairs(checkFolder:GetChildren()) do
if v:IsA("Part") then
v.Touched:Connect(function(plr)
if i == 1 then
checkpoints.Value = 1
if plr.Parent:WaitForChild("Humanoid").Health == 0 then
plr.Parent:WaitForChild("Humanoid").Position = checkFolder.Check1.Position
end
end)
end
end
end
end)

2 comments
Just so you know, one really cheap way to do this (but it works for obbies) is to just use a different team for each stage and use non-neutral spawn locations as checkpoints.
Yes, but i want to keep it in leaderstats. Any way to help?