humanoidRootPart Swings off player when ragdolling after teleport

I want to make it so that it ragdolls normal even after teleporting (editing humanoidRootPart with cframe)

HumanoidRootPart swings around when ragdolling after teleporting

I have tried editing ragdoll script.

ragdoll script:

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local playerHumanoid = character:WaitForChild("Humanoid")
		playerHumanoid.HealthChanged:Connect(function()
			if playerHumanoid.Health < 10.1 then
				local ko = Instance.new('BoolValue')
				ko.Name = "ko"
				ko.Value = true
				ko.Parent = playerHumanoid
				character.Ragdoll1.Disabled = false
				character.Ragdoll2.Disabled = false
				for _, v in pairs(character:GetDescendants()) do
					if v:IsA("Motor6D") then
						local attachment0,attachment1 = Instance.new("Attachment"), Instance.new("Attachment")
						attachment0.CFrame = v.C0
						attachment1.CFrame = v.C1
						attachment0.Parent = v.Part0
						attachment1.Parent = v.Part1
						
						local ballConstraint = Instance.new("BallSocketConstraint")
						ballConstraint.Attachment0 = attachment0
						ballConstraint.Attachment1 = attachment1
						ballConstraint.Parent = v.Part0
						
						v.Enabled = false
					end
				end
				repeat wait() until character.CanGetUp.Value == true
				wait(30)
				for _, v in pairs(character:GetDescendants()) do
					if v:IsA("Motor6D") then
						v.Enabled = true
					elseif v:IsA("BallSocketConstraint") then
						v:Destroy()
					end
				end
				playerHumanoid.ko:Destroy()
				game.ReplicatedStorage.Events.Unragdoll:FireClient(player)
				character.Ragdoll1.Disabled = true
				character.Ragdoll2.Disabled = true
			end
		end)
	end)
end)

robloxapp-20210117-2324555.wmv (3.7 MB)

1 Like

please give any feedback nessary, i do not know what is causing the problem.