Gripping while player is ragdoll'd

I’m trying to have it so that when a player gets knocked down, it ragdoll’s the player. Another player can come up to knocked down player and grip them, the code works but it starts to get all wonky. Here’s a gif:

Gif

Initial grip code:

function KnockdownHandler:Grip()
	local targetEntity = self:ReturnClosestTarget()
	
	if targetEntity.KnockdownHandler.Isknocked ~= true then return end
	if targetEntity.KnockdownHandler.Beingcarried == true then return end
	
	targetEntity.MovementController.speedBuffers["Grip"] = 0
	self.entity.MovementController.speedBuffers["Grip"] = 0
	self.entity.MovementController.jumpBuffers["Grip"] = 0
	self.entity.Busy = true
	self.entity.character.Humanoid.AutoRotate = false
	targetEntity.character.Humanoid.AutoRotate = false
	self.entity.character:SetPrimaryPartCFrame(targetEntity.character.HumanoidRootPart.CFrame * CFrame.new(0,-4,0))
	self.entity.character.HumanoidRootPart.CFrame = CFrame.lookAt(self.entity.character.HumanoidRootPart.Position, Vector3.new(targetEntity.character.HumanoidRootPart.Position.X, targetEntity.character.HumanoidRootPart.Position.Y, targetEntity.character.HumanoidRootPart.Position.Z))
	
	targetEntity.character.HumanoidRootPart.Anchored = true
	
	utilityModule.Ragdoll(targetEntity.character, "Remove", targetEntity)
	
	targetEntity.character.Humanoid.PlatformStand = true
	
	
	task.wait(.5)
	
	local anim2 = self.entity.character.Humanoid.Animator:LoadAnimation(Animations.Grips.FistGrip)
	
	anim2:Play()
	
	local anim = targetEntity.character.Humanoid.Animator:LoadAnimation(Animations.Grips.FistGripped)

	anim:Play()

	anim.Stopped:Wait()
	
	self.entity.character.Humanoid.AutoRotate = true
	targetEntity.character.Humanoid.AutoRotate = true
	
	targetEntity.character.Humanoid.Health = 0
	
	if game.ReplicatedStorage.InPD.Value == true then 
		self.entity.Objects[targetEntity.character]:Wipe(self.entity)
	elseif self.entity.Objects[targetEntity.character].player then 
		self.entity.Data["Slot"..tostring(self.entity.Data.SelectedSlot)].ActionData.PlayerGrips +=1
		self.entity.Objects[targetEntity.character].Data["Slot"..tostring(self.entity.Objects[targetEntity.character].Data.SelectedSlot)].ActionData.Deaths +=1
	end
	
	self.entity.Busy = false
	self.entity.MovementController.speedBuffers["Grip"] = nil
	self.entity.MovementController.jumpBuffers["Grip"] = nil
	
end

Ragdoll Code:

Utility.Ragdoll = function(target, duration, entity)--If duration = "DontRemove" then just creates, if it equals "Remove" then it deltes it, if its a number it just does its thing
	target.Humanoid.PlatformStand = true
	target.Humanoid.RequiresNeck = false 
		
	
	if duration ~= "Remove" then 
		for _, motor in pairs(target:GetDescendants()) do
			if motor:IsA("Motor6D") then
				------------------------------
				local part0 = motor.Part0
				local part1 = motor.Part1
				local attachment0 = Instance.new("Attachment", part0)
				attachment0.Position = (motor.C0).Position

				local attachment1 = Instance.new("Attachment", part1)
				attachment1.Position = (motor.C1).Position

				local socket = Instance.new("BallSocketConstraint")
				socket.LimitsEnabled = true
				socket.MaxFrictionTorque = 100
				socket.Attachment0 = attachment0
				socket.Attachment1 = attachment1			
				socket.Parent = part0
				
				--[[target["Left Leg"].CanCollide = true
				target["Left Arm"].CanCollide = true
				target["Right Leg"].CanCollide = true
				target["Right Arm"].CanCollide = true--]]
				
				
				motor.Enabled = false

				if duration == "DontRemove" then 
					table.insert(entity.ragdollInstances, socket)
					table.insert(entity.ragdollInstances, attachment0)
					table.insert(entity.ragdollInstances, attachment1)
			
				else
					debris:AddItem(socket, duration)			
					task.spawn(function()
						task.wait(duration)
						debris:AddItem(socket, 0) -- just in case
						debris:AddItem(attachment0,0)
						debris:AddItem(attachment1,0)
						
						--[[target["Left Leg"].CanCollide = false
						target["Left Arm"].CanCollide = false
						target["Right Leg"].CanCollide = false
						target["Right Arm"].CanCollide = false--]]
						
						motor.Enabled = true
						target.Humanoid.PlatformStand = false
					end)
				end
				------------------------------
			end
		end		
	end
	
	if duration == "Remove" then 
		---
		for i, v in pairs(entity.ragdollInstances) do 
			debris:AddItem(v)
			table.remove(entity.ragdollInstances, i)
			target.Humanoid.PlatformStand = false
		end
		
		--[[target["Left Leg"].CanCollide = false
		target["Left Arm"].CanCollide = false
		target["Right Leg"].CanCollide = false
		target["Right Arm"].CanCollide = false--]]
		
		for _, motor in pairs(target:GetDescendants()) do
			if motor:IsA("Motor6D") then
				motor.Enabled = true
			end	
		end
		target.Humanoid.PlatformStand = false		
		---
	end
end

In the Initial grip code you are setting the HumanoidRootPart of the target character to be anchored. This means that the part will not be affected by physics, and may cause the character to behave strangely when they are being moved around, so you might try making it unanchored.

If that doesn’t work, in the Ragdoll Code you are creating a number of attachments and motors to create a ragdoll effect on the target character. However, you are not properly storing references to these attachments and motors, so they are being garbage collected and removed from the game after the function finishes executing. This, again, may be causing the character to behave strangely when they are being moved around.
To fix this issue, you can store references to the attachments and motors in a table or an array, and then use this table or array to delete the attachments and motors when you want to remove the ragdoll effect.

If that doesn’t work too try fixing both issues I told you and run them at the same if them one by one don’t work, but I can’t really tell what the issue could be if that doesn’t work.

None of these worked. I’m so confused. Do you think I should resort to rewriting the ragdoll code a lot differently than how it is now?