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

Animation stops when walking/jumping/idle?

Asked by 3 years ago

So I'm making a shooter game and I'm making a reload animation, however when you reload the animation suddenly stops if you try to walk or do any other action. if you stay still it sometimes works but if the second idle animation plays, the reload animation stops again. How do I prevent this from happening? I don't want any leg animations to be overridden by the reload animation, only the arms should be overridden by the reload animation.

(THE LOCAL SCRIPT THAT RUNS THE ANIMATION)

anime = script.Parent.Animation
debounce = false
function play (dah)
    if debounce == false then
        local hum = game.Players.LocalPlayer.Character.Humanoid
        local anim_feet = hum:LoadAnimation(script.Parent.Animation)
        local current = anim_feet
        local hum = game.Players.LocalPlayer.Character.Humanoid
        local animation = anime
        local animationLoad = hum:LoadAnimation(animation)
        animationLoad:Play()
        debounce = true
        wait(1.5) --how long the animation lasts
        debounce = false
        current:Stop()
        end
    end
script.Parent.Activated:Connect(play)

helpfull info: the local script is inside a tool. sometimes when you keep walking the reload will still play, however if you stop walking , the reload animation stops too.

1 answer

Log in to vote
0
Answered by 3 years ago

The answer is to increase the Priority. The priority allows you to play multiple animations at once without them interfering with each other. If you can, go into the Animation Editor and set the priority to Action from the menu where you save and load animations. (don't forget to export the animation again) If you don't want to go into the Animation Editor and change the priority, you can do it from the script side. (but this does not work all of the time)

anime = script.Parent.Animation
debounce = false
function play (dah)
    if debounce == false then
        local hum = game.Players.LocalPlayer.Character.Humanoid
        local anim_feet = hum:LoadAnimation(script.Parent.Animation)
        local current = anim_feet
        local hum = game.Players.LocalPlayer.Character.Humanoid
        local animation = anime
        local animationLoad = hum:LoadAnimation(animation)
        --Set animation priority to action because action is the highest priority
        animationLoad.Priority = Enum.AnimationPriority.Action
        animationLoad:Play()
        debounce = true
        wait(1.5) --how long the animation lasts
        debounce = false
        current:Stop()
        end
    end
script.Parent.Activated:Connect(play)

Hope I helped you resolve your problem.

0
I just noticed you define hum twice, there is no need for that since you are not changing the value. Also why do you define the same animation as both animationLoad and current? And why do you stop a not running animation (current)? vonotige 49 — 3y
Ad

Answer this question