Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I change the running animation of a player while the character is running?

I'm trying to set up a ctrl to run system where the player animation changes when the player is and is not running. I got the script for this working, but the animation for running doesn't change until the player either jumps or idles. How do I make the animation update when the player is running?

Script:

function startPlayerRunning(player)
    if players[player].Vitals.Stamina-1 > 0 then
	    players[player].Vitals.Stamina = players[player].Vitals.Stamina-1
	    runningCharacters[player] = true
	    player.Character.Humanoid.WalkSpeed = runSpeed
	    player.Character.Animate.run.RunAnim.AnimationId = sprintRunAnim
    end
end

  

startRunning.OnServerEvent:Connect(startPlayerRunning)

  

function stopPlayerRunning(player)
    runningCharacters[player] = false
    player.Character.Humanoid.WalkSpeed = defaultSpeed
    player.Character.Animate.run.RunAnim.AnimationId = defaultRunAnim
end

  

stopRunning.OnServerEvent:Connect(stopPlayerRunning)

Gif of issue: https://gyazo.com/a568e571dc4473999ac12f0313c40437

1 answer

I suggest that you use UserInputService to detect whether the player is pressing w,a,s or d and even the arrow keys. Also, to load the animation in, you do this:

local Anim = Instance.new("Animation")

and other code including the :LoadAnimation function. I suggest you watch a YouTube Video about UserInputService. Hope this helps! Edit: After the code in the top, do:

local playAnim = Character.Humanoid:LoadAnimation()

Don't forget to set these variables:

local Player = game.Players.LocalPlayer
local Character = Player.Character

And at the end, do: playAnim:Play()

4 comments

0

I already got userinputservice done client side. I tried loading an animation like that, but the animation speed was too slow and looked clunky after you jumped or something

0

Read my edit please!

0

I got those already as well. I got everything set up. I just need the core running animation to not stutter. Please see the gif I edited onto my question of the issue where the animation doesn't change right away.

0

oh

This discussion is preserved as it was. New answers, comments, and votes are closed.