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

How do I make it stop the animation when it is unequipped?

Asked by 8 years ago
Edited 8 years ago

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.

01local animation = Instance.new('Animation')
02local debounce = false
03 
04function onEquip()
05    script.Parent.Handle.UnsheathSound:Play()
06end
07 
08function 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()
View all 26 lines...
0
It doesn't stop the animation when unequipped... BinaryResolved 215 — 8y
0
Oh sorry, I meant the opposite GatitosMansion 187 — 8y
0
Ok one minute BinaryResolved 215 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

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

01local animation = Instance.new('Animation')
02local debounce = false
03local animTrack
04 
05function onEquip()
06   script.Parent.Handle.UnsheathSound:Play()
07end
08 
09function 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)
View all 32 lines...

Hope this helps you.

Ad

Answer this question