Before you make the code for the animation, you have to create the animation itself in the animation editor made by roblox. Here is a link:
https://www.roblox.com/Animation-Editor-item?id=144373835
Download that plug-in in roblox studio then make your animation. When you make your animation, make sure to name your first and last keyframe (Definitely your last keyframeAfter because this is what will actually be in the code) that, you need to first import your animation in the code, then you have to import your animation via your animation id, then you will be able to actually bind it to a key. Here is a link to everything you need to know about animations:
http://wiki.roblox.com/index.php?title=Animations
At the bottom of the screen, you will see some code that is specifically for animations. That is the code that you want to manipulate. The code will be:
02 | local animation = Instance.new( "Animation" ) |
09 | function playShockAnim(Source) |
11 | local player = game.Players.LocalPlayer.Character |
13 | animTrack = player.Humanoid:LoadAnimation(animation) |
14 | animTrack.KeyframeReached:connect( function (keyframeName) |
15 | if keyframeName = = "ElectrocuteEnd" then |
In this code, what you really want to take out is:
function playShockAnim(Source)
The code that I have is put in a local script in a tool, so what I have is:
1 | local tool = script.Parent |
2 | tool.Equipped:connect( function (mouse) |
3 | mouse.KeyDown:connect( function (key) |
This is what replaces the function playShockAnim(Source)
This is put in a local script in a tool.
The final code would look something like this:
01 | local animation = Instance.new( "Animation" ) |
05 | local tool = script.Parent |
06 | tool.Equipped:connect( function (mouse) |
07 | mouse.KeyDown:connect( function (key) |
09 | key = = "q" and canplay then |
10 | local player = game.Players.LocalPlayer.Character |
12 | animTrack = player.Humanoid:LoadAnimation(animation) |
13 | animTrack.KeyframeReached:connect( function (keyframeName) |
14 | if keyframeName = = "ElectrocuteEnd" then |
That should be all, but like RedCombee said, this is not a request site, you should look at the links i have supported and try to make a little code of your own then show it and then we can help you instead of giving it to you. Anyways, that should be all, hopefully you can get your animation into whatever game you're making. Cheers :)