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

Keydown linked to animations?

Asked by 8 years ago

How do I make a Keydown execute a certain animation such as a dodge to the left of some sort?

1
Scripting Helpers is not a request site. I would suggest going to the roblox wiki to learn about events and the connect function. RedCombee 585 — 8y
0
I actually have quite a lot of experience in keydown linking to animations. Currently i dont have access to my computer, but in a few hours ill be more than happy to help you :) Sparkflyer34 40 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

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:

01-- Import animation
02local animation = Instance.new("Animation")
03animation.AnimationId = "http://www.roblox.com/Asset?ID=144911345" -- Replace the numbers with the numbers from your animation.  It should be in your animation Id.
04 
05-- Local variables
06local animTrack = nil
07local canPlay = true
08 
09function playShockAnim(Source) -- replace this with the key that was pressed
10    if canPlay then
11        local player = game.Players.LocalPlayer.Character
12        canPlay = false
13        animTrack = player.Humanoid:LoadAnimation(animation) -- Load animation into Humanoid
14        animTrack.KeyframeReached:connect(function(keyframeName) -- Bind function to KeyframeReached event
15            if keyframeName == "ElectrocuteEnd" then -- replace this with the name of your last keyframe name.
View all 21 lines...

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:

1local tool = script.Parent
2tool.Equipped:connect(function(mouse)
3mouse.KeyDown:connect(function(key)
4if
5    key == "q" then

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:

01local animation = Instance.new("Animation")
02animation.AnimationId = "http://www.roblox.com/Asset?ID=144911345" -- Replace the numbers with the numbers from your animation.  It should be in your animation Id.
03 
04local canplay = false
05local tool = script.Parent
06tool.Equipped:connect(function(mouse)
07mouse.KeyDown:connect(function(key)
08if
09    key == "q" and canplay then
10    local player = game.Players.LocalPlayer.Character
11        canPlay = false
12        animTrack = player.Humanoid:LoadAnimation(animation) -- Load animation into Humanoid
13        animTrack.KeyframeReached:connect(function(keyframeName) -- Bind function to KeyframeReached event
14            if keyframeName == "ElectrocuteEnd" then -- replace this with the name of your last keyframe name.
15                canPlay = true
16            end
17        end)   
18        animTrack:Play() -- Start the animation
19    end
20end

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 :)

Ad

Answer this question