Respawn on Death Place not working?

Hey there,

I was just trying to make this mechanism where if you die, once you respawn you get teleported back to the place of where you died.

I’m probably stupid, but here’s what I got.

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		Character.Humanoid.Died:Connect(function()
			local tempPos = Character.HumanoidRootPart.Position
			Character.HumanoidRootPart:Destroy()
			repeat task.wait() until Character:WaitForChild("HumanoidRootPart")
			print("Teleported")
			Character.HumanoidRootPart.Position = tempPos
		end)
	end)
end)

Any help is appreciated. Thanks!

Hello!
Once you die the character held in .Character will be deleted, and a new one will be made.
You are trying to set the position of the old deleted character to tempPos.

You need to come up with some new logic that maybe stores the tempPos somewhere (maybe a CFrame value stored in the player, or a dictionary in the script).

Then when the new character is added it will teleport the new character to the correct position.

Hope this helps!

What @RazorWinds_Dev said, but try this.

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
        local spawnPos = nil
        Player.CharacterAdded:Connect(function(Character)
                if spawnpos then
                    Character:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(spawnPos)
                end
                Character.Humanoid.Died:Connect(function()
                        spawnPos = Character.HumanoidRootPart.Position
                    end)
            end)
    end)
local Run = game:GetService("RunService")
local Players = game:GetService("Players")

local DeathPositions = {}

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		Run.Stepped:Wait()
		if DeathPositions[Player] then
			Character:PivotTo(DeathPositions[Player])
		end
		local Humanoid = Character:WaitForChild("Humanoid")
		Humanoid.Died:Connect(function()
			DeathPositions[Player] = Character.PrimaryPart.CFrame
		end)
	end)
end)

Players.PlayerRemoving:Connect(function()
	DeathPositions[Player] = nil
end)