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;
01 | local player = game.Players.LocalPlayer |
02 | repeat wait() until player.Character |
03 | local character = player.Character |
04 | local debounce = false |
05 | local animation = Instance.new( "Animation" ) |
06 |
07 | animation.AnimationId = "rbxassetid://2983973572" |
08 |
09 | local track = character:FindFirstChild( "Humanoid" ):LoadAnimation(animation) |
10 | local UIS = game:GetService( "UserInputService" ) |
11 |
12 | UIS.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 |
22 | 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!
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;
1 | AnimationTrack:Stop() |
and by manipulating it, into your code you just have to change this section of the code;
1 | elseif input.KeyCode = = Enum.KeyCode.R and debounce = = true then |
2 | debounce = false |
3 | track:Play() |
4 | end |
To:
1 | elseif input.KeyCode = = Enum.KeyCode.R and debounce = = true then |
2 | debounce = false |
3 | track:Stop() |
4 | end |
Results: By pressing R the animation will loop and always run, by pressing R again it will stop running.
Hope this helped.