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?

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

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:

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

Answer this question