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

Tool won't stop playing animation upon unequipping?

Asked by 4 years ago

Hi, I'm having an issue with my script. So the script works entirely fine, besides the final part. To sort of explain the script, its designed to where when you equip the gun, it plays the draw animation, immediately followed by the LOOPED stance animation called Idle. When you fire the gun, it plays the fire animation. However, when you unequip the gun, the idle animation continues to play, and I can't get it to stop. Please let me know if you have a solution!

01local Tool = script.Parent
02local fire = Tool.Fire
03local draw = Tool.Draw
04local idle = Tool.Idle
05 
06local AnimateValue = script.Parent.AnimateValue
07 
08Tool.Equipped:connect(function()
09    AnimateValue.Value = true
10    local Character = Tool.Parent
11    local Humanoid = Character.Humanoid
12 
13    local AnimationTrack = Humanoid:LoadAnimation(draw)
14    local AnimationTrack1 = Humanoid:LoadAnimation(idle)
15    if AnimateValue.Value == true then
View all 41 lines...

2 answers

Log in to vote
1
Answered by
Roger111 347 Moderation Voter
4 years ago
Edited 4 years ago

Hi, so a better way to go about this and might as well solve your problem is by adding a variable that tracks the current animation. Then when it is time to stop the animations you will specifically call :Stop() on the animation that is currently playing.

Like so:

01local Tool = script.Parent
02local fire = Tool.Fire
03local draw = Tool.Draw
04local idle = Tool.Idle
05 
06    local currentAnim -- Here is where we add the variable
07 
08local AnimateValue = script.Parent.AnimateValue
09 
10Tool.Equipped:connect(function()
11    AnimateValue.Value = true
12    local Character = Tool.Parent
13    local Humanoid = Character.Humanoid
14 
15    local AnimationTrack = Humanoid:LoadAnimation(draw)
View all 46 lines...
1
Thank you so much! alexduskthorn 40 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

I Think The Problem Is That Your Animation Is LOOPING, You Can UnLoop The Animation By Going InTo The Animation And Turning Off the LOOPING.

Answer this question