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

How do you play an animation on keydown?

Asked by
Irvene 5
10 years ago

I've been trying to figure out animations, and I figured out how to work them. I just can't figure out how to play them when you press a certain key. Help me please!

1 answer

Log in to vote
0
Answered by
Mystdar 352 Moderation Voter
10 years ago

I claim no credit This question has already been answered here: https://scriptinghelpers.org/questions/12609/animation-with-keydown-no-tool Look at other questions before you ask the same one. Either way they did this:

local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/Asset?id=187720963"

local Player = game.Players.LocalPlayer
local Mouse =  Player:GetMouse()
local animTrack = nil

Mouse.KeyDown:connect(function(key)
    if key:lower() == "q" then
        local character = Player.Character
        animTrack = character:WaitForChild("Humanoid"):LoadAnimation(animation) 
        animTrack:Play()
    end
end)
Ad

Answer this question