My character runs in Place

I’m making a running engine but the major issue is that the character runs his animation while staying in place, heres a gif:
https://i.gyazo.com/f10d12135879a5dc165a36fb109d1744.mp4
(yes the fox goes wiggly)
So far I have tried humanoid state types but from what I tried it haven’t worked.
Here is the script i used:


Any suggestions how can I fix the bug?

did you make your animation as action or movement?
I’m just guessing cause that happened to me before

Yes I Have made the animation action.

well then I don’t know whats wrong.

Well I think it has something to do with GetState probably

1 Like

“Running” as a HumanoidState also includes when you’re standing still. You could check the default animation script to see how that handles running animations, or check if the Humanoid’s MoveDirection isn’t 0,0,0 before playing the animation.

So should I change it to RunningNoPhysics or something else?

try this

input.InputBegan:Connect(function(key)
   local k = key.KeyCode
   if k== Enum.KeyCode.LeftShift and h:GetState() == Enum.HumanoidStateType.Running then
      -- ...
  end
end)

It does like a 50/50 precent of running, I want it to run only while the character is moving

Is the animation looped? This is likely your problem.

Also, because it just plays an animation on running, if the animation still is playing when you let it go, it will look unnatural. If you want to fix that, stop the animation on InputEnded event if the animation is still playing with animation:Stop().

So should I make the animation not looped?

Yes, you are not stopping the animation ever in the code, it would be obvious to not set it looped if you can’t stop it.

Using GetState in my cases have proven to be very unreliable if you want to make the character stop the animation when you’re still, I’d recommend the Running event and checking if the speed is 0.

Can you please give an example of how to do so? I checked the roblox developer site and still coludn’t really understand how to use it for the player to run while his speed is not 0

And I have tried unlooping it but the character just runs for a couple of seconds and then stop

Checking for the velocity of the player’s HumanoidRootPart would suffice. Example:


local uis = game:GetService("UserInputService")
local character = game.Players.LocalPlayer.Character;
local root = character:WaitForChild("Humanoid");



local run = game:GetService("RunService");

run.RenderStepped:Connect(function(dt)
    uis.InputBegan:Connect(function(inp, gpe)
        if gpe then return; end

        if not (root.Velocity.Magnitude > 0) then runAnim:Stop(); return; end;

        if inp.KeyCode == Enum.KeyCode.K then
           
           if runAnim.IsPlaying then return; end
           if final.IsPlaying then return; end

           runAnim:Play();
           final:Play();
       end
    end)

    uis.InputEnded:Connect(function(inp, gpe)
        if gpe then return; end

        if inp.KeyCode == Enum.KeyCode.K then
            if runAnim.IsPlaying or final.IsPlaying then return; end

            runAnim:Stop(); final:Stop();
        end
    end
end

this may not be the best method, but it works (haven’t tested it yet though)

(I used final for tween service)

change final.IsPlaying to final.PlaybackState == Enum.PlaybackState.Playing or final.PlaybackState.Completed

Optionally, you can shorten these by defining a variable with it

local playing = Enum.PlaybackState.Playing;
local completed = Enum.PlaybackState.Completed;

What do you mean?

If you mean how it looks unnatural because it doesn’t stop when you stop holding the shift button, you have to manually stop it with InputEnded event connected function as I said before.

I’ve experienced this issue before, the problem is that the animation still plays even when the player isn’t moving, which is clearly unwanted. So while my solution may not be the best or well-optimised, I’m pretty certain it’d work