Each call of my ragdoll function makes every other function in the characterhandler script exponentially laggier

I had a ragdoll function that caused lag whenever it was called. I replaced it with a modified version of another ragdoll script I found here, but this one also causes extreme server lag and spikes the activity and rate except it increases with each call. The first time it’s called is fine, same with the second except the activity gets higher and each time it’s called the rate and activity gets higher and higher until about ragdoll call #15 where it gets to this:


Even after ragdoll #15 is over and the activity % goes back down to 0, the rate still stays that high and any other unrelated function in this characterhandler script or input (even simply pressing w to walk or double tapping space to climb) brings the activity % up to between 5-25%.

Server:

--Ragdoll
function Joints()
	for _,v in pairs(character:GetDescendants()) do
		if v:IsA("Motor6D") and v.Name ~= "WeaponMotor" and v.Name ~= "HiltMotor" and v.Name ~= "HeadMotor" and v.Name ~= "CarryMotor" and v.Name ~= "HoodMotor" then
			local b = Instance.new("BallSocketConstraint", v.Parent)
			local a0, a1 = Instance.new("Attachment"), Instance.new("Attachment")
			a0.Parent, a1.Parent = v.Part0, v.Part1
			b.Attachment0, b.Attachment1 = a0, a1
			a0.CFrame, a1.CFrame = v.c0, v.c1
			b.LimitsEnabled = true
			b.TwistLimitsEnabled = true
			b.Enabled = false
		end
	end
end

Joints()

function ragdoll()
	remotesFolder:WaitForChild("Ragdoll"):FireClient(player)
	humanoid.AutoRotate = false
	for _,v in pairs(character:GetDescendants()) do
		if v:IsA("Motor6D") and v.Name ~= "WeaponMotor" and v.Name ~= "HiltMotor" and v.Name ~= "HeadMotor" and v.Name ~= "CarryMotor" and v.Name ~= "HoodMotor" and v.Name ~= "RootJoint" then
			v.Enabled = false
		elseif v:IsA'BallSocketConstraint' then
			v.Enabled = true
		end
	end
end

function unRagdoll()
	remotesFolder:WaitForChild("UnRagdoll"):FireClient(player)
	humanoid.AutoRotate = true
	for _,v in pairs(character:GetDescendants()) do
		if v:IsA'Motor6D' then
			v.Enabled = true
		elseif v:IsA'BallSocketConstraint' then
			v.Enabled = false
		end
	end
end	

Local:

--Ragdoll
local function ragdoll()
	humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp,false)
	humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)
	character.Humanoid.BreakJointsOnDeath = false
	character.Humanoid.RequiresNeck = false
end

local function unRagdoll()
	humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp,true)
	humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
	character.Humanoid.BreakJointsOnDeath = true
	character.Humanoid.RequiresNeck = true
end

remotesFolder:WaitForChild("Ragdoll").OnClientEvent:Connect(ragdoll)
remotesFolder:WaitForChild("UnRagdoll").OnClientEvent:Connect(unRagdoll)