So, when the player dies, I want them to go back to the checkpoint they touched. I used a code and i don't know what the problem is and I am a bit confused on how to get this working. Any ideas on how? Here is my script I Wrote:
local checkFolder = game.Workspace.checkpoints
game.Players.PlayerAdded:Connect(function(plr) --// just defining the folder leaderstats
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local checkpoints = Instance.new("IntValue") --// making a value in a folder called checkpoints
checkpoints.Name = "Stages"
checkpoints.Parent = leaderstats
for i,v in pairs(checkFolder:GetChildren()) do
if v:IsA("BasePart") then
v.Touched:Connect(function(plr)
local humanoid = plr.Parent:FindFirstChild("Humanoid")
if i == 1 then
checkpoints.Value = 1
humanoid.Died:Connect(function()
plr:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(v.Position + Vector3.new(0,2,0)) --// this is where i get confused as it doesn't work. Any ideas?
end)
end
end)
end
end
end)
I tried using CFrame and made it the position of the checkpoint plus 2 on the "y" axis.
The For i,v in pairs part is finding all children in the folder checkFolder. Please help me

5 comments
try characteradded instead of died
Ok i will
It doesn't work :( Could you please explain this further? Do i have to use a parameter for this?
Use "if humanoid.Health == 0 then"
I tried that but it didn't work