Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would i make a player teleport to a checkpoint when they die?

Asked by 5 years ago

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:

01local checkFolder = game.Workspace.checkpoints
02 
03game.Players.PlayerAdded:Connect(function(plr) --// just defining the folder leaderstats
04    local leaderstats = Instance.new("Folder")
05    leaderstats.Name = "leaderstats"
06    leaderstats.Parent = plr
07 
08    local checkpoints = Instance.new("IntValue") --// making a value in a folder called checkpoints
09    checkpoints.Name = "Stages"
10    checkpoints.Parent = leaderstats
11 
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")
View all 25 lines...

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

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

1 answer

Log in to vote
0
Answered by
Lakodex 711 Moderation Voter
5 years ago
Edited 5 years ago

Here. It was simple...

01local checkFolder = game.Workspace.checkpoints
02 
03game.Players.PlayerAdded:Connect(function(plr) --// just defining the folder leaderstats
04    local leaderstats = Instance.new("Folder")
05    leaderstats.Name = "leaderstats"
06    leaderstats.Parent = plr
07 
08    local checkpoints = Instance.new("IntValue") --// making a value in a folder called checkpoints
09    checkpoints.Name = "Stages"
10    checkpoints.Parent = leaderstats
11 
12    for i,v in pairs(checkFolder:GetChildren()) do
13        if v:IsA("BasePart") then
14            v.Touched:Connect(function(plr)
15        local char = plr.Character or plr.CharacterAdded:Wait() --// Didn't add this to wait for the character
View all 25 lines...
0
But, now when the player dies, they go straight to the checkpoint and then when their character is fixed, they will go to spawn. Please any way to stop this? kingblaze_1000 359 — 5y
Ad

Answer this question