Introduction
If you didn't know, there's a function of a Tool
. That's called...
Activated
and Deactivated
.
What are they?
To put it simply, it's a function in which it detects when the player has clicked and un-clicked their mouse.
1 | Tool.Activated:Connect( function () |
5 | Tool.Deactivated:Connect( function () |
Procedures
With this, you can have an animation (that's looped, of course) that will play inside of the tool.
So, for the final procedures, follow these steps.
1) Insert a LocalScript
inside of the Tool
.
2) Get your looped animation ID and get the Humanoid defined as a variable.
3) With your variables, write this:
01 | local Animation = Instance.new( "Animation" ,script.Parent) |
03 | Animation.Name = "Whatever you want to name this" |
04 | local Humanoid = game.Players.LocalPlayer.Character:WaitForChild( 'Humanoid' ) |
06 | local Anim = Humanoid:LoadAnimation(Animation) |
08 | Tool.Activated:Connect( function () |
12 | Tool.Deactivated:Connect( function () |
However, there is a flaw with this. When you unequip it, the animation keeps playing. So now, let's use the .Unequipped
function.
01 | local Animation = Instance.new( "Animation" ,script.Parent) |
03 | Animation.Name = "Whatever you want to name this" |
04 | local Humanoid = game.Players.LocalPlayer.Character:WaitForChild( 'Humanoid' ) |
06 | local Anim = Humanoid:LoadAnimation(Animation) |
08 | Tool.Activated:Connect( function () |
12 | Tool.Deactivated:Connect( function () |
16 | Tool.Unequipped:Connect( function () |
Conclusion
Voila! I really hope I taught you something today. You're welcome! :)
~Sensei_Developer