Ragdoll problems with npc

https://gyazo.com/cb0bf3cef0b7471e86a41ac37c3ba688
When the npc get up the animation is still playing and froze like that idk why
Here’s the script

local runService = game:GetService("RunService")
local char = script.Parent
local fx = char:WaitForChild("Effects")
local hum = char:WaitForChild("Humanoid")
local HRP = char:WaitForChild("HumanoidRootPart")

local torso = char:WaitForChild("UpperTorso")

local fallen
local ragdolled = false

fx.ChildAdded:Connect(function(c)
	if c.Name == "Ragdoll" and not ragdolled then
		
		for i,v in pairs(hum:GetPlayingAnimationTracks()) do
			v:Stop()
		end
		
		ragdolled = true 

		hum:ChangeState(Enum.HumanoidStateType.Physics)

		-------------------------------------------------------------
		for _,v in pairs(char:GetDescendants()) do
			if v:IsA("Motor6D") then
				if v.Name ~= "Root" and v.Name ~= "RootJoint" then
					local att0 = Instance.new("Attachment")
					att0.Name = "RagdollSocket"
					att0.CFrame = v.C0
					att0.Parent = v.Part0
					local att1 = Instance.new("Attachment")
					att1.Name = "RagdollSocket"
					att1.CFrame = v.C1
					att1.Parent = v.Part1

					local socket = script.RagdollJoints:FindFirstChild(v.Name)
					socket.Attachment0 = att0
					socket.Attachment1 = att1
					socket.Enabled = true

					v.Enabled = false
				end
			end
		end

		HRP.CanCollide = false
		HRP.Massless = true

		-------------------------------------------------------------
	end
end)

fx.ChildRemoved:Connect(function(c)
	if c.Name == "Ragdoll" and fx:FindFirstChild(c.Name) == nil then 
		for i,v in pairs(hum:GetPlayingAnimationTracks()) do
			v:Stop()
		end
		hum:ChangeState(Enum.HumanoidStateType.GettingUp)
		ragdolled = false
		--------------------------------------------------
		local sockets = {}
		for _,v in pairs(char:GetDescendants()) do
			if v:IsA("Motor6D") then
				v.Enabled = true
			elseif v.Name == "RagdollSocket" then 
				table.insert(sockets,v)
			elseif v.Parent.Name == "RagdollJoints" then
				v.Enabled = false
			end
		end

		for _,v in pairs(sockets) do v:Destroy() end

		HRP.CanCollide = true
		HRP.Massless = false
		return true
		------------------return true--------------------------------
		
	end
end)

Hope ypu guys can help me :sunglasses: