I am a bit confused about my script. Because the detecting part works perfectly and the teleport command is also logical, but I when I test it then it will detect if the player died but will not teleport the player to that location.
Here is my script (print(“Success!”) is because for testing if the detecting part works):
game.Players.PlayerAdded:Connect(function(player) print(player) local spawn = false script.Parent.Touched:Connect(function(hit) print("Success!") if hit.Parent:FindFirstChild("Humanoid") and hit.Parent.Name == player.Name then spawn = true end end) player.CharacterAdded:Connect(function(character) print("Success!") if spawn == true then print("Success!") character.HumanoidRootPart.CFrame = CFrame.new(script.Parent.Position.X,script.Parent.Position.Y+5,script.Parent.Position.Z) end end) end)
My script is a script, not a local or module script. If you know why it is not working, then please point it out for me. I do not need how to make a checkpoint, I just need why is this not working. If you know then please tell me, thanks.
I have a checkpoint for my script and it's working so use that:
local Players = game:GetService("Players") local spawn = script.Parent script.Parent.Touched:Connect(function(hit) local player = game.Players:GetPlayerFromCharacter(hit.Parent) if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then local checkpointData = game.ServerStorage:FindFirstChild("CheckpointData") if not checkpointData then checkpointData = Instance.new("Model", game.ServerStorage) checkpointData.Name = "CheckpointData" end local checkpoint = checkpointData:FindFirstChild(tostring(player.userId)) if not checkpoint then checkpoint = Instance.new("ObjectValue", checkpointData) checkpoint.Name = tostring(player.userId) player.CharacterAdded:connect(function(character) wait() character:WaitForChild("UpperTorso").CFrame = game.ServerStorage.CheckpointData[tostring(player.userId)].Value.CFrame + Vector3.new(0, 4, 0) end) end checkpoint.Value = spawn end end)