Player character teleporting after death

I have a spawn object that can be placed in a player’s room. It is supposed to teleport the player to it when they die or first join, however when they die it teleports them to a random position within the map before they die, then it teleports them to the spawn. I am not sure what is causing this bug, but I know it is one of the teleport lines. Any help would be much appreciated.

Room.PlacedObjects.ChildAdded:Connect(function(child)
	if child.Name == "Spawn Pad" then
		local Player = Players:FindFirstChild(Owner.Value)
		if Player then
			local Character = Player.Character or Player.CharacterAdded:Wait()
			wait()
			Character.HumanoidRootPart.Position = child.Body.TPPart.Position 
			Character.HumanoidRootPart.CFrame = CFrame.new(Character.HumanoidRootPart.CFrame.Position) * CFrame.Angles(0, child.Body.TPPart.Orientation.Y, 0)
			Player.CharacterAdded:Connect(function(character)
				wait()
				character.HumanoidRootPart.Position = child.Body.TPPart.Position
				character.HumanoidRootPart.CFrame = CFrame.new(character.HumanoidRootPart.CFrame.Position) * CFrame.Angles(0, child.Body.TPPart.Orientation.Y, 0)
			end)
		end
	end
end)

Maybe you’d be able to make use of Player | Roblox Creator Documentation

1 Like

I think your issue is that you are setting the position of the character and then setting the CFrame immediately after. I’ve noticed setting positions of parts can act weird when another part is in the way so just in general I’d recommend only reading from the .Position value of a part and writing to it’s CFrame.
As for the code you can actually just do:

character.HumanoidRootPart.CFrame = child.Body.TPPart.CFrame

(completely remove the .Position line)
CFrame takes into account orientation as well so the * CFrame.Angles() is not needed

2 Likes