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

Animation stops when walking/jumping/idle?

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

✓ Accepted answer

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.

1 comment

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)?

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