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)
01 | anime = script.Parent.Animation |
02 | debounce = false |
03 | function play (dah) |
04 | if debounce = = false then |
05 | local hum = game.Players.LocalPlayer.Character.Humanoid |
06 | local anim_feet = hum:LoadAnimation(script.Parent.Animation) |
07 | local current = anim_feet |
08 | local hum = game.Players.LocalPlayer.Character.Humanoid |
09 | local animation = anime |
10 | local animationLoad = hum:LoadAnimation(animation) |
11 | animationLoad:Play() |
12 | debounce = true |
13 | wait( 1.5 ) --how long the animation lasts |
14 | debounce = false |
15 | current:Stop() |
16 | end |
17 | end |
18 | 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.
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)
01 | anime = script.Parent.Animation |
02 | debounce = false |
03 | function play (dah) |
04 | if debounce = = false then |
05 | local hum = game.Players.LocalPlayer.Character.Humanoid |
06 | local anim_feet = hum:LoadAnimation(script.Parent.Animation) |
07 | local current = anim_feet |
08 | local hum = game.Players.LocalPlayer.Character.Humanoid |
09 | local animation = anime |
10 | local animationLoad = hum:LoadAnimation(animation) |
11 | --Set animation priority to action because action is the highest priority |
12 | animationLoad.Priority = Enum.AnimationPriority.Action |
13 | animationLoad:Play() |
14 | debounce = true |
15 | wait( 1.5 ) --how long the animation lasts |
16 | debounce = false |
17 | current:Stop() |
18 | end |
19 | end |
20 | script.Parent.Activated:Connect(play) |
Hope I helped you resolve your problem.