Ragdolling Fling issue

The issue I facing is that when I ragdoll the enemy and then unragdoll them. It flings the enemy or if it doesn’t fling the npc just falls flat on the ground for like 3 seconds…

Please watch the video it’s pretty self explanatory the issue : Watch 2024-07-09 17-07-10 | Streamable

this is the ragdolling script

local module = {}
local Players = game:GetService("Players")
local PhysicsService = game:GetService("PhysicsService")
local ragParts = script.Parent.RagdollParts:GetChildren()

PhysicsService:RegisterCollisionGroup("Ragdoll")
PhysicsService:CollisionGroupSetCollidable("Ragdoll", "Default", true)

function module:Setup(char: Model)
	assert(
		Players:GetPlayerFromCharacter(char) == nil,
		"Setting up ragdoll on player characters is already done automatically"
	)

	local humanoid = char:FindFirstChild("Humanoid")
	assert(humanoid, "Can only set-up ragdoll on R6 humanoid rigs")
	assert(humanoid.RigType == Enum.HumanoidRigType.R6, "Can only set-up ragdoll on R6 humanoid rigs")
	assert(humanoid.RootPart ~= nil, "No RootPart was found in the provided rig")
	assert(char:FindFirstChild("HumanoidRootPart"), "No HumanoidRootPart was found in the provided rig")

	for _, v: BasePart in ipairs(char:GetDescendants()) do
		if v:IsA("BasePart") then
			v:SetNetworkOwner(nil)
		end
	end

	-- Setup ragdoll
	char.Head.Size = Vector3.new(1, 1, 1)
	humanoid.BreakJointsOnDeath = false
	humanoid.RequiresNeck = false

	-- Clean up previous RagdollConstraints folder if it exists
	if char:FindFirstChild("RagdollConstraints") then
		char.RagdollConstraints:Destroy()
	end

	local clones = {}
	for _, v in ipairs(ragParts) do
		clones[v.Name] = v:Clone()
	end

	local folder1 = Instance.new("Folder")
	folder1.Name = "RagdollConstraints"
	for _, v in pairs(clones) do
		if v:IsA("Attachment") then
			v.Parent = char[v:GetAttribute("Parent")]
		elseif v:IsA("BallSocketConstraint") then
			v.Attachment0 = clones[v:GetAttribute("0")]
			v.Attachment1 = clones[v:GetAttribute("1")]
			v.Parent = folder1
		end
	end
	folder1.Parent = char

	local folder2 = Instance.new("Folder")
	folder2.Name = "Motors"
	local value
	for _, v in ipairs(char.Torso:GetChildren()) do
		if v:IsA("Motor6D") then
			value = Instance.new("ObjectValue")
			value.Value = v
			value.Parent = folder2
		end
	end
	folder2.Parent = folder1

	-- Ragdoll trigger
	if not char:FindFirstChild("RagdollTrigger") then
		local trigger = Instance.new("BoolValue")
		trigger.Name = "RagdollTrigger"
		trigger.Parent = char

		trigger.Changed:Connect(function(bool)
			if bool then
				module:Ragdoll(char)
			else
				module:Unragdoll(char)
			end
		end)
	end
end

function module:Ragdoll(char: Model)
	char.Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
	char.Humanoid.RequiresNeck = false
	char.Humanoid.AutoRotate = false
	char.Humanoid.PlatformStand = true
	char.Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)

	for _, v in ipairs(char.RagdollConstraints.Motors:GetChildren()) do
		v.Value.Enabled = false
	end
	task.delay(0.05, function()
		for _, v in ipairs(char:GetChildren()) do
			if v:IsA("BasePart") then
				v.CollisionGroup = "Ragdoll"
				v.Anchored = false
				v.CanCollide = true
			end
		end
	end)

	char.HumanoidRootPart:ApplyAngularImpulse(Vector3.new(-90, 0, 0))
end

function module:Unragdoll(char: Model)
	char.Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
	char.Humanoid.PlatformStand = false
	char.Humanoid:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, false)

	for _, v in ipairs(char.RagdollConstraints.Motors:GetChildren()) do
		v.Value.Enabled = true
	end

	for _, v in ipairs(char:GetChildren()) do
		if v:IsA("BasePart") then
			v.CollisionGroup = "Default"
			v.Anchored = false
			v.CanCollide = true
		end
	end
	char.Humanoid.AutoRotate = true

	char.HumanoidRootPart.Velocity = Vector3.new(0,0,0)
	char.HumanoidRootPart.RotVelocity = Vector3.new(0,0,0)
end

return module