Some cloned characters spasm out when ragdolled

For some reason my ragdoll clone script isnt working right because sometimes in some characters, especially ones with layered clothing, they start to spasm out. I tried setting network ownership to not the player, changing humanoid state to ragdoll, GettingUp false, and setting Platform stand false but nothing is working! The first clip is what is supposed to happen, but the second with the girl is what is not supposed to happen and it doesnt work with the girl for some reason.

Video of working ragdoll:

Video with spasming ragdoll and different character:

Ragdoll Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ragdollEvent = ReplicatedStorage:WaitForChild("RagdollEvent")
local BindableEvent = ReplicatedStorage:WaitForChild("GrimaceShakeDeath")
local BindableEvent2 = ReplicatedStorage:WaitForChild("GrimaceShakeDeath2")
local nofly = ReplicatedStorage:WaitForChild("nofly")


local c = script.Parent
c.Archivable = true
c.Humanoid.BreakJointsOnDeath = false

local character1 = script.Parent
local humanoid = character1:WaitForChild("Humanoid")
character1.Archivable = true

local function ragdoll(target)
	for i, v in pairs(target:GetDescendants()) do
		if v:IsA("Motor6D") then
			local a0, a1 = Instance.new("Attachment"), Instance.new("Attachment")
			a0.CFrame = v.C0
			a1.CFrame = v.C1
			a0.Parent = v.Part0
			a1.Parent = v.Part1
			local k = Instance.new("BallSocketConstraint")
			k.Attachment0 = a0
			k.Attachment1 = a1
			k.Parent = v.Part0
			v:Destroy()
		end
		if v:IsA("BasePart") and v ~= target.HumanoidRootPart then
			v.CanCollide = true
		end
	end
	target.HumanoidRootPart.CanCollide = false
end

BindableEvent2.Event:Connect(function(character)
	local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
	if humanoid then
		for _, track in pairs(humanoid:GetPlayingAnimationTracks()) do
			track:Stop()
		end
	end
	local clonedChar = character:Clone()
	local stringValue = Instance.new("StringValue") -- Create a new StringValue
	stringValue.Value = "clone" -- Assign the string "clone" to the StringValue
	stringValue.Parent = clonedChar -- Set the parent of the StringValue to be clonedChar
	clonedChar.Humanoid.HealthDisplayType = "AlwaysOff"
	--ragdollEvent:FireAllClients(clonedChar)
	for i, v in pairs(character:GetDescendants()) do
		if v:IsA("BasePart") then
			v.Massless = false
			v.CollisionGroup = "Default"
		end
	end
	clonedChar.HumanoidRootPart.Anchored = false
	local player = game.Players:GetPlayerFromCharacter(character)
	character:Destroy()
	clonedChar.Parent = workspace  -- Parent the clone to the workspace
	nofly:Fire(clonedChar)
	for i,v in pairs(clonedChar:GetDescendants()) do
		if v:IsA("BasePart") then 
			v:SetNetworkOwner(nil) 
		end
	end
	ragdoll(clonedChar)
	print("Avatar ownership revoked")
	--for i,v in pairs(clonedChar:GetDescendants()) do
		--if v:IsA("BasePart") then v:SetNetworkOwner(nil) end
	--end

	clonedChar.Humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)
	clonedChar.Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
	wait(1)
	clonedChar.HumanoidRootPart.Anchored = true
	wait(2)  -- Wait for 3 seconds
	player:LoadCharacter()  -- Respawn the player
	wait(57)
	clonedChar:Destroy()
end)

No fly script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local nofly = ReplicatedStorage:WaitForChild("nofly")

nofly.Event:Connect(function(clonedChar)
	while true do
		clonedChar.Humanoid.Sit = true
		clonedChar.Humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)
		clonedChar.Humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
		clonedChar.Humanoid.PlatformStand = false
		wait()
	end
end)

Script that freezes ragdoll after it’s still:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local nofly = ReplicatedStorage:WaitForChild("nofly")
local BindableEvent = ReplicatedStorage:WaitForChild("Frozen")
local Lol = ReplicatedStorage:WaitForChild("GrimaceShakeDeath")

nofly.Event:Connect(function(clonedChar)
	local model = clonedChar
	local parts = model:GetDescendants()
	local lastPositions = {}
	local stationaryTime = {}

	for _, part in pairs(parts) do
		if part:IsA("BasePart") then
			lastPositions[part] = part.Position
			stationaryTime[part] = 0
		end
	end

	while wait(1) do
		local allPartsStationary = true
		for _, part in pairs(parts) do
			if part:IsA("BasePart") then
				local currentPos = part.Position
				local lastPos = lastPositions[part]
				if (currentPos - lastPos).Magnitude > 1 then
					allPartsStationary = false
				else
					stationaryTime[part] = stationaryTime[part] + 1
				end
				lastPositions[part] = currentPos
			end
		end

		if allPartsStationary then
			local allPartsTouching = true
			for _, part in pairs(parts) do
				if part:IsA("BasePart") then
					local touchingParts = part:GetTouchingParts()
					for _, touchingPart in pairs(touchingParts) do
						if not touchingPart:IsDescendantOf(model) and not touchingPart.CanCollide then
							allPartsTouching = false
							break
						end
					end
				end
				if not allPartsTouching then
					break
				end
			end

			if allPartsTouching then
				for _, part in pairs(parts) do
					if part:IsA("BasePart") and stationaryTime[part] > 0 then
						part.Anchored = true
					end
				end
			end
		end
	end
	Lol:Fire(clonedChar)
end)