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
Here. It was simple...
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 char = plr.Character or plr.CharacterAdded:Wait() --// Didn't add this to wait for the character local humanoid = char.Parent:WaitForChild("Humanoid") --// You said "FindFirstChild". If the player was not loaded I'd automatically cancel itself and return an error. if i == 1 then checkpoints.Value = 1 humanoid.Died:Connect(function() char:WaitForChild("HumanoidRootPart").CFrame = v.CFrame * CFrame.new(0, 3, 0) --// Part should be fixed end end) end end end)