What is the best way to detect if a HumanoidState is active?


Achieve

To make it a bit more clear, I’m attempting to detect when a player is in the Physics state. I want it to detect that while every other state can be activated whenever needed.

Issue

My current issue is that when a player touches this brick, and is ragdolled… they get damaged during the first ragdoll, but not any other ragdolls past that.

Workaround

There is only one workaround currently and that’s if I disable every other State and never re-enable the said states. This then causes the issue where it always damages… which isn’t the goal.

Script

local delay = false

script.Parent.Touched:Connect(function(hit)
	if delay == false then
		if hit.Parent then
			if hit.Parent:FindFirstChild("Humanoid") then
				local char = hit.Parent
				local CurrentState = char.Humanoid:GetState()
				if CurrentState == Enum.HumanoidStateType.Physics then
					delay = true
					char.Humanoid.Health = char.Humanoid.Health - 7
					wait(3)
					delay = false
					print("Delay is now false")
					print(delay)
				else
					warn(CurrentState)
				end
			end
		end
	end
end)

Thank you for any help you can give me.

I created an attribute to fix this issue. Getting states to trigger certain things to happen, such as a ragdoll; isn’t reliable to read as it is in constant change.