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

Animation stop playing when another Animation plays?

Asked by 6 years ago

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;

01local player = game.Players.LocalPlayer
02repeat wait() until player.Character
03local character = player.Character
04local debounce = false
05local animation = Instance.new("Animation")
06 
07animation.AnimationId = "rbxassetid://2983973572"
08 
09local track = character:FindFirstChild("Humanoid"):LoadAnimation(animation)
10local UIS = game:GetService("UserInputService")
11 
12UIS.InputBegan:connect(function(input,proc)
13        if not proc then
14            if input.KeyCode == Enum.KeyCode.R and debounce == false then
15                debounce = true
16                track:Play()
17        elseif input.KeyCode == Enum.KeyCode.R and debounce == true then
18            debounce = false
19            track:Play()
20         end
21     end
22end)

(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

Log in to vote
0
Answered by
Divistern 127
6 years ago

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;

1AnimationTrack:Stop()

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

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

To:

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

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

Hope this helped.

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! QwertyPython 2 — 6y
0
Happy this helped! Divistern 127 — 6y
Ad

Answer this question