How would i make a player teleport to a checkpoint when they die?
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:
01 | local checkFolder = game.Workspace.checkpoints |
03 | game.Players.PlayerAdded:Connect( function (plr) |
04 | local leaderstats = Instance.new( "Folder" ) |
05 | leaderstats.Name = "leaderstats" |
06 | leaderstats.Parent = plr |
08 | local checkpoints = Instance.new( "IntValue" ) |
09 | checkpoints.Name = "Stages" |
10 | checkpoints.Parent = leaderstats |
12 | for i,v in pairs (checkFolder:GetChildren()) do |
13 | if v:IsA( "BasePart" ) then |
14 | v.Touched:Connect( function (plr) |
15 | local humanoid = plr.Parent:FindFirstChild( "Humanoid" ) |
18 | humanoid.Died:Connect( function () |
19 | plr:WaitForChild( "HumanoidRootPart" ).CFrame = CFrame.new(v.Position + Vector 3. new( 0 , 2 , 0 )) |
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