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

Animation stop playing when another Animation plays?

I don't really know how to explain this, but I'll try my best. Basically, I have an animation I'm currently working on;

local player = game.Players.LocalPlayer
repeat wait() until player.Character
local character = player.Character
local debounce = false
local animation = Instance.new("Animation")

animation.AnimationId = "rbxassetid://2983973572"

local track = character:FindFirstChild("Humanoid"):LoadAnimation(animation)
local UIS = game:GetService("UserInputService")

UIS.InputBegan:connect(function(input,proc)
	    if not proc then
		    if input.KeyCode == Enum.KeyCode.R and debounce == false then
			    debounce = true
			    track:Play()
		elseif input.KeyCode == Enum.KeyCode.R and debounce == true then
			debounce = false
			track:Play()
		 end
	 end
end)

(Now is it just me or does copy pasta not work with the codeblocks here?)

The animation played is just a simple movement of the left arm, but I want it to continue playing until the key is pressed again. However if I idle, jump, move, climb, get hurt, etc. it stops the animation. I've searched everywhere but I don't know how to word it to find it.

Thanks in advance for the help!

1 answer

✓ Accepted answer

You can do this by setting your animation's Priority And to to change it you'll have to go to the tab "Settings" in the animation Editor then click on set priority and change it to;

Action: Which is used in overriding any running animation with the current selected one, Means that this animation when it's played, it will always be on top of other animations

Do not forget to tag the "Toggle Looping Animation" next to the animation Play button, And you could just stop the animation by using;

AnimationTrack:Stop()

and by manipulating it, into your code you just have to change this section of the code;

elseif input.KeyCode == Enum.KeyCode.R and debounce == true then
	debounce = false
	track:Play()
end

To:

elseif input.KeyCode == Enum.KeyCode.R and debounce == true then
	debounce = false
	track:Stop()
end

Results: By pressing R the animation will loop and always run, by pressing R again it will stop running.

Hope this helped.

2 comments

0

Thanks a lot for this, I had already changed the code to track:Stop() but I just didn't have the Priority set right, thanks a million, for such a simple answer to haha!

0

Happy this helped!

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