How to prevent a rig from being flung after PlatformStand is set to false?

Hello, I’ve been trying to make a ragdoll system for my fighting game, as some weapons in the game ragdoll the hit humanoid, however sometimes whenever the character gets up, they fling up in the air, sometimes even more than once, before landing and getting up.

Here is my code:

local function ragdoll(char:Model,humanoid:Humanoid)
	humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, false)
	humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)
	humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)

	humanoid.PlatformStand = true

	for i,joint in pairs(char:GetDescendants()) do
		if typeof(joint) == "Instance" and joint:IsA("Motor6D") then
			local attach1 = Instance.new("Attachment")
			attach1.CFrame = joint.C0
			attach1.Parent = joint.Part0

			local attach2 = Instance.new("Attachment")
			attach2.CFrame = joint.C1
			attach2.Parent = joint.Part1

			local socket = Instance.new("BallSocketConstraint")
			socket.Attachment0 = attach1
			socket.Attachment1 = attach2
			socket.LimitsEnabled = true
			socket.TwistLimitsEnabled = true
			socket.Parent = joint.Parent

			joint.Enabled = false
		end
	end
end

local function unragdoll(char:Model,humanoid:Humanoid)
	for i,thing in pairs(char:GetDescendants()) do
		if typeof(thing) == "Instance" then
			if thing:IsA("BallSocketConstraint") then
				thing:Destroy()
			elseif thing:IsA("Motor6D") then
				thing.Enabled = true
			end
		end
	end
	humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, true)
	humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, true)
	humanoid:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, false)
	humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)
	
	--preventFling(char)
	humanoid.PlatformStand = false

	humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
end

I’ve tried many solutions on the devforum, such as disabling the Ragdoll and FallingDown humanoid states, but to no avail.

(please keep in mind that players aren’t the only ones that can get ragdolled, as there are npcs and enemies in the game too, so client-side solutions won’t really be so useful.)