How do you fix body parts moving unusual?

I’m trying to just have the character walk/move normally after the script has been executed.

After using the script on a player the limbs seem to somewhat go into place but it looks slightly off including the animation.

for i,v in pairs(game.Players:GetChildren()) do
	--if v.Character and v.UserId ~= game.Players.LocalPlayer.UserId then
		
		local HRP = v.Character:FindFirstChild('HumanoidRootPart')
		for char,e in pairs(v.Character:GetChildren()) do
			if e:IsA('BasePart') then
				if e.Name ~= HRP.Name and HRP.Parent:FindFirstChild('Humanoid'):GetState() ~= Enum.HumanoidStateType.Dead  then
					e.Orientation = Vector3.new(0,0,0)
					if e.Name == "Head" then
						e.Position = HRP.Position + Vector3.new(0,1.5,0)
					elseif e.Name == "Torso" then
						e.Position = HRP.Position
					elseif e.Name == "Left Arm" then
						e.Position = HRP.Position + Vector3.new(-1.5,0,0)
					elseif e.Name == "Left Leg"  then
						e.Position = HRP.Position + Vector3.new(-.5,-2,0)
					elseif e.Name == "Right Arm" then
						e.Position = HRP.Position + Vector3.new(1.5,0,0)
					elseif e.Name == "Right Leg" then
						e.Position = HRP.Position + Vector3.new(.5,-2,0)
					end
				end
			end
		end
		
	--end
end

This is the code I used to realign all the body parts, the reason I have this is because when a player rejoins the ragdoll I have setup in the game will not look the same from the client (their body will be messed up most of the time), so I’m trying to make the limbs forcefully go back into place when the player joins.

I don’t know why the body moves like this after the script was executed tho.

Why don’t you save the position of all the parts before the ragdoll, then put them back to that after?

the joint sin the rig are rotated the wrong way
if the head is backwards rotate the neck joint 180 degrees (do this with other joints until it is fixed)