Ragdoll behaving differently every time characters health is <= 0

Working on a ragdoll system and every time the Character.Humanoid.Health is <= 0 the joints on my ragdoll lock up. Here is a clip so you know what I’m talking about: Watch joints lock up on death | Streamable

Here is my ragdoll module script:

local RagdollHandler = {}

function RagdollHandler.BuildJoints(char)
	local hrp = char:WaitForChild("HumanoidRootPart")

	for i,v in pairs(char:GetDescendants()) do
		if not v:IsA("BasePart") or v:FindFirstAncestorOfClass("Accessory") or v.Name == "Handle" or v.Name == "Torso" or v.Name == "HumanoidRootPart" then continue end

		if not m_ragdollinfo[v.Name] then continue end

		local a0 = Instance.new("Attachment")
		local a1 = Instance.new("Attachment")
		local joint = Instance.new("BallSocketConstraint")

		a0.Name = "RAGDOLL_ATTACHMENT"
		a0.Parent = v
		a0.CFrame = m_ragdollinfo[v.Name].CFrame[2]

		a1.Name = "RAGDOLL_ATTACHMENT"
		a1.Parent = hrp
		a1.CFrame = m_ragdollinfo[v.Name].CFrame[1]

		joint.Name = "RAGDOLL_CONSTRAINT"
		joint.Parent = v
		joint.Attachment0 = a0
		joint.Attachment1 = a1

		v.Massless = true
	end
end

function RagdollHandler.WeightlessCharacter(char)
	for i,v in pairs(char:GetChildren()) do
		if v:IsA("BasePart") then
			v.Massless = true
			v.CanCollide = false
		end
	end
end

function RagdollHandler.EnableCollisionParts(char, enabled)
	for i,v in pairs(char:GetChildren()) do
		if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then
			v.CanCollide = not enabled
			v.Collide.CanCollide = enabled
		end
	end
end

function RagdollHandler.EnableMotor6D(char, enabled)
	for i,v in pairs(char:GetDescendants()) do
		if v.Name == "Handle" or v.Name == "RootJoint" or v.Name == "Neck" then continue end
		if v:IsA("Motor6D") then v.Enabled = enabled end
	end
end

workspace:GetDescendants()

function RagdollHandler.SetupHumanoid(hum)
	hum.BreakJointsOnDeath = false
	hum.RequiresNeck = false
	hum:SetStateEnabled(Enum.HumanoidStateType.Dead, false)
end

function RagdollHandler.BuildCollisionParts(char)
	for i,v in pairs(char:GetChildren()) do
		if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" then
			local p = v:Clone()
			p.Parent = v
			p.CanCollide = false
			p.Massless = true
			p.Size = Vector3.one
			p.Name = "Collide"
			p.Transparency = 1
			--p.CustomPhysicalProperties.Friction = 0.8
			--p.CustomPhysicalProperties.Friction = 0.8
			p:ClearAllChildren()

			local weld = Instance.new("WeldConstraint", p)
			weld.Part0 = v
			weld.Part1 = p
		end
	end
end

function RagdollHandler.DestroyJoints(char)
	char.HumanoidRootPart.Massless = false

	for i,v in pairs(char:GetDescendants()) do
		if v.Name == "RAGDOLL_ATTACHMENT" or v.Name == "RAGDOLL_CONSTRAINT" then v:Destroy() end

		if not v:IsA("BasePart") or v:FindFirstAncestorOfClass("Accessory") or v.Name == "Torso" or v.Name == "Head" then continue end
	end
end

function RagdollHandler.UnragdollCharacter(char)
	local plr = Players:GetPlayerFromCharacter(char)
	local hum = char:WaitForChild("Humanoid")
	local hrp = char:WaitForChild("HumanoidRootPart")

	if plr then
		re_clientragdoll:FireClient(plr, "Unragdoll")
	else
		hrp:SetNetworkOwner(nil)
		if hum:GetState() == Enum.HumanoidStateType.Dead then return end
		hum.PlatformStand = false
		hum:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)
		hum:ChangeState(Enum.HumanoidStateType.GettingUp)
	end

	char:SetAttribute("Ragdoll", false)
	RagdollHandler.DestroyJoints(char)
	RagdollHandler.EnableMotor6D(char, true)
	RagdollHandler.EnableCollisionParts(char, false)
end

function RagdollHandler.RagdollCharacter(char, duration)
	local plr = Players:GetPlayerFromCharacter(char)
	local hum = char:WaitForChild("Humanoid")
	local hrp = char:WaitForChild("HumanoidRootPart")
	if not hrp then return end

	char:SetAttribute("Ragdoll", true)
	RagdollHandler.EnableMotor6D(char, false)
	RagdollHandler.BuildJoints(char)
	RagdollHandler.EnableCollisionParts(char, true)

	if plr then
		re_clientragdoll:FireClient(plr, "Ragdoll")
	else
		hrp:SetNetworkOwner(nil)
		hum.AutoRotate = false
		hum.PlatformStand = true
	end

	if not duration then return end
end

return RagdollHandler

and here is how I’m calling it:

re_knock.OnServerEvent:Connect(function(player)
	local char = player.Character or player.CharacterAdded:Wait()
	local hum = char:WaitForChild("Humanoid")
	local hrp = char:WaitForChild("HumanoidRootPart")
	local root_joint = hrp:WaitForChild("RootAttachment")

	local vel = Instance.new("LinearVelocity", hrp)
	vel.MaxForce = 1000000
	vel.Attachment0 = root_joint
	vel.VectorVelocity = hrp.CFrame.lookVector * -25

	Debris:AddItem(vel, .1)

	m_ragdollhandler.RagdollCharacter(char)
	task.wait(1)
	hum.Health = 0
	char:SetAttribute("Knocked", true)
end)

Bumping since its been close to a day with no solution

For anyone having this issue I had to run:

hum:SetStateEnabled(Enum.HumanoidStateType.Dead, false)

On the client every time I ran the ragdoll function.