Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why is Humanoid:GetState() returning "Running" even though the character is standing still?

Asked by 2 years ago
Edited 2 years ago

I am trying to make a breathing script where if the player is walking it would make a breathing particle every one second the problem is that Humanoid:GetState() is returning "Running" even though the player is standing still or vise versa. This is the script I used so you can see if there are any problems inside of it, It is a serverscript placed inside serverscript service

local BreathingParticle = game.ReplicatedStorage.BreathingParticle

game.Players.PlayerAdded:Connect(function(player)   
    player.CharacterAdded:Connect(function(Char)    
        local Head = Char:WaitForChild("Head")  
        local Hum = Char.Humanoid

        local Particle = BreathingParticle:Clone()
        Particle.Rate = 0
        Particle.Parent = Head.FaceFrontAttachment


        repeat
            if Hum:GetState() == Enum.HumanoidStateType.Running then -- Problem here
                print(Hum:GetState())
                Particle:Emit(1)
            end

            wait(1)
        until false
    end)
end)

someone please help!! its very annoying

1 answer

Log in to vote
1
Answered by 2 years ago

So it is very weird, but I'm pretty sure that Humanoid.Running runs whenever the character moves. This also means when they are not moving using the movement keys. EX: They get hit with a bomb and they go flying, they are not techincally moving, but their velocity is high so Humanoid.Running runs.

So there is one way you can rewrite your code to make it work. I am assuming you are acting upon a player so here is the rewritten code using MoveDirection.

local BreathingParticle = game.ReplicatedStorage.BreathingParticle

game.Players.PlayerAdded:Connect(function(player)   
    player.CharacterAdded:Connect(function(Char)    
        local Head = Char:WaitForChild("Head")  
        local Hum = Char.Humanoid

        local Particle = BreathingParticle:Clone()
        Particle.Rate = 0
        Particle.Parent = Head.FaceFrontAttachment


        while true do
        if hum.MoveDirection.Magnitude > 0.2 then -- magnitude is length of vector
            Particle:Emit(1)
        else
            -- something to do when its not running. 
        end
        wait()
    end
    end)
end)

In case you are wondering, Humanoid.Running runs in your code because the character bobs up and down. If you stand still you can see the animation that plays, I am 99% sure that is why Humanoid.Running runs.

Ad

Answer this question