If character is hit in mid-air, character's rotation = unfrozen?

So I am trying to make it so that when my character hits something in mid-air, like a railing, the rotation constraint will be taken off, and the character will go flipping through the air until he has stopped sufficiently. I have worked out most of the code, but for some reason even though I have it set to have the script enabled when grounded, the script is disabled when grounded. I don’t know why. Here is the block that says this:

		enabled = true;
		rigidbody.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationY | RigidbodyConstraints.FreezeRotationZ;

The second part says that when grounded the rotation restraints are restored.

IDK, im new at this, but you could try to check if the player.gameObject is on the terrain or what ever object is deemed ground by adding a new var and then when the character is in the air, make it true, then use rigidbody.contraints on the x axis, as you have done. And then when the player is on the ground change the var back to being true so the rigidbody doesn’t affect the player/whatever object until it is in the air again