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

What's the best way to play an animation on click?

Asked by 4 years ago

This is my first approach. But this seems stuttering a lot for me. What's the best and simplest way?

1script.Parent.Equipped:Connect(function(mouse)
2    mouse.Button1Down:Connect(function()
3        local slash = game.Players.LocalPlayer.Character.Humanoid:LoadAnimation(script.Slash)      
4    end)
5end)

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Hello. The problem is that you did not :Play() the animation. Also, I'd use Tool.Activated as it fires when a Tool is clicked and it just saves you lines of code. Here is the code that will work:

1script.Parent.Activated:Connect(function()
2        local slash = game:GetService("Players").LocalPlayer.Character.Humanoid:LoadAnimation(script.Slash)
3        slash:Play()      
4    end)
5end)
Ad

Answer this question