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)