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

How would I make a animation play from a tool?

Asked by
Nozazxe 107
4 years ago
Edited 4 years ago

I know how to do it, but it just loops even when I unequip the tool. I have a animation in my tool that I made, and I have a script in it that says

01local tool = script.Parent
02local toolanim = tool.Animation
03 
04tool.Activated:Connect(function()
05local char = tool.Parent
06local hum = char.Humanoid
07 
08local AnimationTrack = hum:LoadAnimation(toolanim)
09AnimationTrack:play()
10end)

1 answer

Log in to vote
2
Answered by 4 years ago

Hello.

The reason as to why your animation is looping is either, you set the wrong animation priority, or, you haven't told it to stop the animation when you unqeuipped your tool. This is very simple to do with the .Unequipped function. This function will call anytime the tool is unequipped. From there, we can tell the tool to stop the animation. I also reccomend to Load the animation before you activate the tool, and also use the Humanoid.Animator instead of just the humanoid, as that is deprecated.

Here is an example with your script:

01local Tool = script.Parent
02local ToolAnimation = Tool.Animation
03 
04local Character = Tool.Parent
05local Humanoid = Character.Humanoid
06 
07local Animation = Humanoid.Animator:LoadAnimation(ToolAnimation)
08 
09Tool.Activated:Connect(function()
10    Animation:Play()
11end)
12 
13Tool.Unequipped:Connect(function()
14    Animation:Stop()
15end)

Hope this helps!

0
Thanks Mate! Nozazxe 107 — 4y
Ad

Answer this question