Ragdoll starts to fly when player jumps

Im trying to fix an event-based ragdoll script that has been in my game for a long time.

whenever the player gets ragdolled, as long as they hold the jump button they are able to position their ragdolled character upright and start flying into the air. This continues until the ragdolling stops.

Ive tried to use the Humanoid state type “physics” yet it doesnt do anything. Ive also tried enabling platformstand. My last resort is setting the humanoids jumppower to 0, but not even that solved my issue.

local PS = game:GetService("PhysicsService")

game.ServerStorage.EquinoxEngineAssets.Ragdoll.Event:Connect(function(char, ragdolltime)
	if char.Name == "" then --things i dont want to be ragdolled
		return
	else
		local collidearms = char.RagdollClient.CollideArms
		local collidelegs = char.RagdollClient.CollideLegs
		if collidelegs.Disabled==true then
			local ws = char.Humanoid.WalkSpeed
			local jp = char.Humanoid.JumpPower
			local permjp=jp
			char.Humanoid.JumpPower=0
			char.Humanoid.RequiresNeck=false
			char.Humanoid.BreakJointsOnDeath=false
			local player = game.Players:FindFirstChild(char.Name)
			for i,v in pairs(char:GetDescendants()) do
				if v:IsA("Motor6D") then
					local socket = Instance.new("BallSocketConstraint")
					local a1 = Instance.new("Attachment")
					local a2 = Instance.new("Attachment")
					a1.Parent = v.Part0
					a2.Parent = v.Part1
					socket.Parent = v.Parent
					socket.Attachment0 = a1
					socket.Attachment1 = a2
					a1.CFrame = v.C0
					a2.CFrame = v.C1
					socket.LimitsEnabled = true
					socket.TwistLimitsEnabled = true
					socket.MaxFrictionTorque = 15
					socket.UpperAngle = 0.5
					
					v.Enabled = false
				end
			end
			
			local up=game.ServerStorage.EquinoxEngineAssets.standUp:Clone()
			game.Debris:AddItem(up, 2)
			
			
			collidearms.Disabled = false
			collidelegs.Disabled = false
			
			char:FindFirstChild("HumanoidRootPart").CanCollide=false
			
			if char:FindFirstChild("HumanoidRootPart") and char.HumanoidRootPart:FindFirstChild("RootJoint") and char.HumanoidRootPart.RootJoint.Enabled == false then
				char:FindFirstChild("HumanoidRootPart").RootJoint.Enabled = true
			end
	
			
			char.Humanoid.AutoRotate = false
			
			task.wait(ragdolltime)
			for i,v in pairs(char:GetDescendants()) do
				if v:IsA("BallSocketConstraint") then
					v:Destroy()
				end
				if v:IsA("Motor6D") then
					v.Enabled = true
				end
			end
			
			local down=game.ServerStorage.EquinoxEngineAssets.standDown:Clone()
			game.Debris:AddItem(down, 2)
			
			if char.Humanoid.WalkSpeed == ws then
				char.Humanoid.WalkSpeed = ws
			end
			if char.Humanoid.JumpPower == 0 then
				char.Humanoid.JumpPower = permjp
			end
		
			

			local getup = script.GettingUp:Clone()
			getup.Parent = char
			getup.Disabled = true
			game.Debris:AddItem(getup, 2)
	
			collidearms.Disabled = true
			collidelegs.Disabled = true
	
			char.Humanoid.AutoRotate = true
			
			char.HumanoidRootPart.Orientation=Vector3.new(0,0,0)
		end
	end
end)

standUp and standDown are localscripts that set the physics statetype for the humanoid, before anyone asks.
thanks!

edit: it turns out the character doesnt start to fly upward because of jumping (sorta)
jumping just positions the character upright, but its the fact that its upright that causes it to fly. As long as the character is upright, it doesnt matter if they are jumping or not, they will start flying into the air. They have to be mid-air for them to start flying, if they are on the ground then they arent going to start flying.
robloxapp-20230420-2301431.wmv (3.5 MB)

First, check if the code that sets the Physics state type for the humanoid is working properly. Since you’re using local scripts to handle this, make sure they are being executed at the right time.

Secondly, ensure that the humanoid’s JumpPower is being set to 0 when the player is ragdolled. You currently set the JumpPower to 0, but then immediately set it back to its original value if it’s not already 0. To disable the player’s ability to jump while ragdolled, make sure that the JumpPower remains at 0 until the player is no longer ragdolled.

Thirdly, check if the platformstand property is set correctly. According to the Roblox Developer Hub, this property can prevent the humanoid from falling over while standing still, but it won’t prevent the humanoid from falling over when colliding with other objects or when being moved by external forces.

Lastly, check if there’s any other part of your code that could be interfering with the player’s ability to control their ragdolled character. For instance, if you have code that disables the player’s ability to move or rotate while ragdolled, this could prevent them from being able to position themselves upright.

I dont think you understand, i dont want the player character to position upright. As they hold spacebar while ragdolled and mid-air, the avatar positions itself upright and then starts to fly into the air. I just want the ragdoll to act according to roblox’s physics.

and yes, the physics statetype works correctly. And no, the jumppower doesnt immediatly set itself back to 0. It waits until the task.wait is over, then sets it back to the original value in order to unragdoll the player.

Could just disable (unbind) jumping altogether through ContextActionService

local ContextActionService = game:GetService("ContextActionService")
ContextActionService:UnbindAction("jumpAction")

unbind it whenever they enter a ragdoll state, rebind it whenever you need jumping enabled, etc etc

and if you want players to be able to jump in the ragdoll state then add a debounce/raycast check for when they hit the ground

i just found out it isnt because of jumping, its because the player is simply in an upright position. Jumping just causes it to become upright.

sorry for the sudden edit.