Need help fixing bug with players being unable to stand up after being ragdolled


the bug is in the video: the players get “roblox-default ragdolled” (not sure how else to describe it) after the ragdoll effect from my scripts end. the bug seems to happen randomly, and players go back to normal when they respawn (the bug can happen multiple times, though). can someone help me figure out why this is happening? i can’t tell if its caused by something with my damage/ragdoll module scripts, the model of the weapon or the player’s animations…

if you need anymore info to help fix the issue, just ask and ill give it
ragdoll module script:

local ragdoll = {}

function ragdoll.Start(character)
	--ensure Ragdoll BoolValue exists
	local ragdollValue = character:FindFirstChild("Ragdoll")
	if not ragdollValue then
		ragdollValue = Instance.new("BoolValue")
		ragdollValue.Name = "Ragdoll"
		ragdollValue.Parent = character
	end

	if ragdollValue.Value then return end
	ragdollValue.Value = true

	for _, joint in pairs(character:GetDescendants()) do
		if joint:IsA("Motor6D") then
			local part0 = joint.Part0
			local part1 = joint.Part1
			if part0 and part1 then
				local socket = Instance.new("BallSocketConstraint")
				local a0 = Instance.new("Attachment")
				local a1 = Instance.new("Attachment")
				a0.CFrame = joint.C0
				a1.CFrame = joint.C1
				a0.Parent = part0
				a1.Parent = part1
				socket.Attachment0 = a0
				socket.Attachment1 = a1
				socket.Parent = joint.Parent
				socket.LimitsEnabled = true
				socket.TwistLimitsEnabled = true

				joint.Enabled = false
				
			end
		end
	end

	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		humanoid.WalkSpeed = 0
		humanoid.JumpPower = 0
		humanoid.PlatformStand = true
		humanoid.AutoRotate = false
	else
		print("no humanoid found in character")
	end
end

function ragdoll.Stop(character)
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if humanoid then
		humanoid.PlatformStand = false

		for _, joint in pairs(character:GetDescendants()) do
			if joint:IsA("BallSocketConstraint") then
				joint:Destroy()
			elseif joint:IsA("Motor6D") then
				joint.Enabled = true
			end
		end

		local ragdollValue = character:FindFirstChild("Ragdoll")
		if ragdollValue then
			ragdollValue.Value = false
		end

		humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
		humanoid.WalkSpeed = 24
		humanoid.JumpPower = 50
		humanoid.AutoRotate = true
	else
		print("no humanoid found in character")
	end
end

return ragdoll

damage script (this uses the ragdoll effect functions from the module):

--parenting stuff involving the player
local tool = script.Parent
tool.Equipped:Connect(function()
	local character = tool.Parent
	charhrp = character.HumanoidRootPart
end)
local bat = tool.BatModel
local damage_re = tool:WaitForChild("SwingEvent")
local hitsound = bat.BatHit

--call modules
local ragdollmodule = require(game:GetService("ServerScriptService").RagdollModule)
local kbmodule = require(game:GetService("ServerScriptService").KnockbackModule)

--set up stuff for hitbox
local hitbox = Instance.new("Part",tool)
local hitlist = {} --hitlist = the enemies that the hitbox makes contact with

--inflict damage, knockback and ragdoll
local function inflict_damage(other_object)
	
	if not hitlist[other_object.Parent] then --check if the parent has already been seen
		local humanoid = other_object.Parent:FindFirstChild("Humanoid") --enemy humanoid
		
		if humanoid then
			hitlist[other_object.Parent] = true --This can be anything other than nil or false.  It's the value we get back when we ask what is inside hitlist[other_object.Parent].  It will be nil if it doesn't exist, but will be true in this case if it does exist in the hitlist.
			humanoid:TakeDamage(25) --deal damage
			
			if humanoid.Health > 0 then
				ragdollmodule.Start(humanoid.Parent)--begin ragdoll
			end
			
			--inflict knockback
			local kbforce = 60 --hor. strength
			local upwardforce = 50 --vert. strength
			kbmodule.Start(humanoid.Parent, (charhrp.CFrame.LookVector * kbforce + Vector3.new(0,upwardforce,0))) --deal knockback w/ upward force
			
			--play damage sound for each enemy hit
			for i in hitlist do
				hitsound:Play()
			end
			--end ragdoll
			wait(2)
			ragdollmodule.Stop(humanoid.Parent)
			
		end
		
	end
	
end

damage_re.OnServerEvent:Connect(function() --run function when remote event is triggered by swinging bat
	local hitbox = Instance.new("Part",tool) --make hitbox
	
	--hitbox properties
	hitbox.Size = Vector3.new(1,5,1)
	hitbox.CanCollide = false
	hitbox.Massless = true
	hitbox.Transparency = 0.7 --debug

	--make hitbox move w/ the bat (welds n stuff)
	local weld = Instance.new("Weld",hitbox)
	weld.Part0 = bat
	weld.Part1 = hitbox
	game.Debris:AddItem(hitbox,0.4) --make hitbox disappear after some time

	hitlist = {} --resets hitlist by creating a new list
	
	hitbox.Touched:Connect(inflict_damage)
end)

--i got this script on youtube: https://www.youtube.com/watch?v=kb0zcUA7OMg&ab_channel=ManlyCreator
--changes from the original were made by me and this dude tlr22 on the devforum so props 2 him