Can't detect player swimming when ragdolled

Hello! i’m doing drowning system for my game. System uses “Humanoid.StateChanged”
everything is works fine until player got ragdolled. When player got ragdolled, drowning system not works

Video about it:

Drowning Script - (Server Script):

Humanoid.StateChanged:Connect(function(Old, New)
	if New == Enum.HumanoidStateType.Swimming and Character:FindFirstChild("Head") then
		Character.Stamina.Swimming.Value = true
		repeat 
			wait()
			Character.Stamina.Value -= 0.5
		until Character.Stamina.Swimming.Value == false or Character.Stamina.Value <= 0
		if Character.Stamina.Value <= 0 then
			repeat
				wait(1)
				if Character.Stamina.Swimming.Value == true then
					Humanoid:TakeDamage(15) 
					Character.Head.DrowningSound.PlaybackSpeed = math.random(90, 115) / 100
					Character.Head.DrowningSound:Play()
				end
			until Character.Stamina.Swimming.Value == false or Humanoid.Health <= 0
		end
	else
		Character.Stamina.Swimming.Value = false
	end
end)

How can i fix this?

That’s because being ragdolled and swimming are different HumanoidStateTypes . What you want to do is find the HumanoidStateType when you’re ragdolled and also factor that into your script. One way to find out the HumanoidStateType of being ragdolled is to just print out the humanoidstatetype when you’re ragdolled.
I.e.

Humanoid.StateChanged:Connect(function(old, new)
print(new) -- it'll print out the humanoidstatetype of being ragdolled 
end)
1 Like

Sorry, i didn’t understand. Can you give an example? from mine script.