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.
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)