Answered by
5 years ago Edited 5 years ago
To make an animation, you need an animation object. If you want to learn more about animation tracks, click here
Use LocalScript
& add script to tool
I'm going to explain everything with detail so that I'm not just throwing in a script.
If you don't already have animation object then do add one or add a variable like this to create one.
1 | local AnimObj = Instance.new( "Animation" , (Choose parent)) |
To get animation track, you need to have an animation object. You might already have that. If so, then locate your animation and make it a variable. Also player. For example,
1 | local player = game:GetService( "Players" ).LocalPlayer |
2 | local AnimObj = workspace.AnimationA |
And then you can find Character from LocalPlayer. Also Humanoid
is needed. Once again, this is a LocalScript
1 | local player = game:GetService( "Players" ).LocalPlayer |
2 | local AnimObj = workspace.AnimationA |
3 | local char = player.Character or player.CharacterAdded:Wait() |
4 | local humanoid = char:WaitForChild( "Humanoid" ) |
Now we need an AnimationTrack, so, let's create a new variable.
1 | local player = game:GetService( "Players" ).LocalPlayer |
2 | local AnimObj = workspace.AnimationA |
3 | local char = player.Character or player.CharacterAdded:Wait() |
4 | local humanoid = char:WaitForChild( "Humanoid" ) |
5 | local AnimTrac = humanoid:LoadAnimation(AnimObj) |
Time to set Priority to Movement, so it plays over the original holding animtion, if you already did this in Animation editor then good, but if you didn't, there's a property in AnimationTrack
which is Priority, so add this to the script:
1 | AnimTrack.Priority = Enum.AnimationPriority.Movement |
Finally, let's use the Tool.Activated
event and play animation. That's when the player clicks. If you want to learn more then click here.
1 | AnimTrack.Priority = Enum.AnimationPriority.Movement |
2 | script.Parent.Activated:Connect( function () |
You can add debounce
if you want, but i'll leave it here, you can add what you want, I hope you learned something new, and I hope this worked for you.