Strange ragdoll behaviour

Hello,

for the past day or so I was trying to fix my ragdoll system. For some reason, the player just hangs in the air, can walk around and their limbs can collide with objects despite the fact, that I used Humanoid:ChangeState() to set it to Ragdoll.

I searched almost everywhere for a solution, but couldn’t find anything. (DevForum, Developer Hub, YouTube). I ran out of ideas on how to fix this so here I am.

What do you want to achieve?
When player gets hit by a specific object, they will ragdoll and recover after some time (just the ragdoll is broken, the object is done)

I have 2 scripts: A module script in ServerScriptService (keeping the functions), and a local script in character (changing the state types).

this is what it looks like
Capture.PNG
Output during testing
Capture2

Module:

function m.ragActivate(plr,duration)
	if plr and plr.Character and plr.Character:FindFirstChildOfClass("Humanoid") and plr.Stats.Loaded.Value == true and plr.Character.Humanoid:FindFirstChild("Stunned") == nil then
		local char = plr.Character
		local human = char:WaitForChild("Humanoid")
		local tag = Instance.new("BoolValue",char.Humanoid)
		tag.Value = true; tag.Name = "Stunned"
		for i,v in pairs(char:GetDescendants()) do -- Go through character and edit contraints
			if v:IsA("BallSocketConstraint") then
				v.Enabled = true
			elseif v:IsA("Motor6D") then
				if v.Parent == char.Torso then
					v.Enabled = false
				end
			elseif v:IsA("BasePart") then
				if v:CanSetNetworkOwnership() then
					v:SetNetworkOwner(nil)
				end
			end
		end
		game.ReplicatedStorage.Events.ClientRagdoll:FireClient(plr,true) -- tell client to enable ragdoll
		delay(duration,function() -- disable ragdoll after some time
			human["Stunned"]:Remove()
			for i,v in pairs(char:GetDescendants()) do
				if v:IsA("BallSocketConstraint") then
					v.Enabled = false
				elseif v:IsA("Motor6D") then
					if v.Parent == char.Torso then
						v.Enabled = true
					end
				elseif v:IsA("BasePart") then
					if v:CanSetNetworkOwnership() then
						v:SetNetworkOwner(plr)
					end
				end
			end
			char.Humanoid.WalkSpeed = game.StarterPlayer.CharacterWalkSpeed
			char.Humanoid.AutoRotate = true
			game.ReplicatedStorage.Events.ClientRagdoll:FireClient(plr,false)
			return
		end)
	end
end

Local Script:

game.ReplicatedStorage.Events.ClientRagdoll.OnClientEvent:Connect(function(state)
	if human.Health > 0 then
		if state == true then -- enabled
			human:ChangeState(Enum.HumanoidStateType.Ragdoll)
			human:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
		elseif state == false then -- disabled
			human:SetStateEnabled(Enum.HumanoidStateType.GettingUp,true)
		end
	end
end)

while wait(.1) do -- debug stuff
	print(human:GetState())
end

Any help regarding this problem would be very appreciated!

i solved it… somehow
I just disabled RootJoint and then enabled it again and it works
I don’t know why this works but hey…