Localscript not working

I have no idea why this script makes the animations jitter
Here is the script:

local UIS = game:GetService('UserInputService')
local Player = game.Players.LocalPlayer
local Character = Player.Character
local raAnim = nil
local daAnim = nil
local aAnim = Instance.new('Animation')
aAnim.AnimationId = 'rbxassetid://'
local bAnim = Instance.new('Animation')
bAnim.AnimationId = 'rbxassetid://'
raAnim = Character.Humanoid:LoadAnimation(aAnim)
daAnim = Character.Humanoid:LoadAnimation(bAnim)
local minspeed = 18
local medspeed = 30
Character.Humanoid.Running:Connect(function(speed)
if speed >= minspeed and speed < medspeed then
raAnim:Play()
daAnim:Stop()
elseif speed >= medspeed then
daAnim:Play()
raAnim:Stop()
else
raAnim:Stop()
daAnim:Stop()
end
end)

note: I removed the animation id’s

Try re-arranging your animation play and stop orders in your if statements. Like this:

daAnim:Stop()
raAnim:Play()

tried but the animations still jitter

Send a gyazo gif showing the animations jitter.

Oh I figured it out. The issue here is your function keeps running since you are using Humanoid.Running to keep constantly checking whether or not their speed matches up but it will keep replaying the same thing. To fix this add a checker to your statements so they won’t play again if they are already currently playing until they finish running.

local checkPlaying = false
Character.Humanoid.Running:Connect(function(speed)
  if speed >= minspeed and speed < medspeed and checkPlaying == false then
    checkplaying = true
    raAnim:Play()
    daAnim:Stop()
  elseif speed >= medspeed then
    daAnim:Play()
    raAnim:Stop()
    checkplaying = false -- alows for speed to animation increase to be played again
  else -- would recommend adding something other than just else because if you have multiple checkers that don't let either bits of code run through it will force its way here.
    raAnim:Stop()
    daAnim:Stop()
end
end)

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