How to make an animation in tool script? Like when I equip a tool and then left-click, an animation would trigger. How would I make that?
I am at school atm, this means I can't test this code. Let me know if there are any problems.
PLEASE read the comments!
01 | --// In LocalScript |
02 |
03 | local Player = game.Players.LocalPlayer --finds player |
04 | local Character = Player.Character or Player.CharacterAdded:Wait() --find player's character, if not, waits for character to be added |
05 |
06 | TOOL.Equipped:Connect( function () --when we equip the tool |
07 | TOOL.Activated:Connect( function () --when we click when having the tool equipped |
08 | local Anim = Instance.new( 'Animation' , Character) --makes animation |
09 | Anim.AnimationId = 000000000 --id here |
10 |
11 | PlayAnim = Character.Humanoid:LoadAnimation(Anim) --this is a global variable so that we can call the "Stop()" function to stop the animation outside the Equipped function. |
12 | PlayAnim:Play() |
13 | end ) |
14 | end ) |
15 |
16 | TOOL.UnEquipped:Connect( function () --when we unequip the tool |
17 | PlayAnim:Stop() |
18 | end ) |
1 | script.Parent.Equipped:connect( function (namewhat) |
2 | script.Parent.Activated:connect( function (click) |
3 | -- animation script here |
4 | end ) |
5 | end ) |