How do I make it stop the animation when it is unequipped? Please rewrite my script because it is messy, but you don't have too. Thanks for reading.
01 | local animation = Instance.new( 'Animation' ) |
02 | local debounce = false |
03 |
04 | function onEquip() |
05 | script.Parent.Handle.UnsheathSound:Play() |
06 | end |
07 |
08 | function onActivate() |
09 | if not debounce then |
10 | debounce = true |
11 | script.Parent.Handle.SlashSound:Play() |
12 | animation.AnimationId = "http://www.roblox.com/asset/?id=129967390" |
13 | local player = game.Players.LocalPlayer.Character |
14 | local animTrack = player.Humanoid:LoadAnimation(animation) |
15 | animTrack:Play() |
It's extremely simple, make it so the animTrack
can be accessed across more than one function. We do this by declaring it outside the function onActivate()
. Then we create a function to get when the tool is unequipped. Then we use :Stop()
on animTrack
.
All together now
01 | local animation = Instance.new( 'Animation' ) |
02 | local debounce = false |
03 | local animTrack |
04 |
05 | function onEquip() |
06 | script.Parent.Handle.UnsheathSound:Play() |
07 | end |
08 |
09 | function onActivate() |
10 | if not debounce then |
11 | debounce = true |
12 | script.Parent.Handle.SlashSound:Play() |
13 | animation.AnimationId = "http://www.roblox.com/asset/?id=129967390" |
14 | local player = game.Players.LocalPlayer.Character |
15 | animTrack = player.Humanoid:LoadAnimation(animation) |
Hope this helps you.