How to neutralise/cancel out a Humanoid’s state

I’m anchoring the humanoid root part after I detect a wall via raycasts. And I’m setting the humanoid state to physics right before anchoring it.

However, whenever I jump down into a wall, the last state before changing it to physics is freefalling. This causes some of its animations to carry over and the falling sound continues.
How can I cancel these things out?

humanoid.StateChanged:Connect(function(oldState,newState)
   if newState == Enum.HumanoidStateType.FreeFall and raycast then
      humanoid:ChangeState(Enum.HumanoidStateType.Idle) -- you can change this value to however you like
      --override the animation and sound if not in freefall
      --anchor as soon as the player goes into idle
   end
end)
1 Like

How would you do this line? I suppose you just play a new animation but how do u override the sound?

You can create this in the same script by creating two boolean values that determines whether a sound is being played or not, whether a player is in free fall or not.

local sound = -- any sound
local isSoundPlaying = sound.IsPlaying()
if isSoundPlaying == true and humanoid:GetState() ~= Enum.HumanoidStateType.FreeFall then
   sound:Pause()
else
   sound:Play()
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.