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

How can I trigger an animation on key hit?

Asked by 9 years ago

I created an animation (that is on the ROBLOX site now, I had to pay 30 R$) that I would like to play when a player presses the W or UP arrow key on the keyboard, but I do not know how to do this.

Any help?

Thank you!

0
Are you looking to trigger an animation if someone moves?(script.Parent.Parent.Character.HumanoidRootPart.Velocity is how fast the player is moving if the script is in the backpack.) Thelegendofbrio13 0 — 5y

1 answer

Log in to vote
0
Answered by 9 years ago
local animation = Instance.new("Animation")
animation.AnimationId = "animation ID" -- ex http.robloxblahblah
local animTrack = Humanoid:LoadAnimation(animation)

function onKeyDown(key)
    key = key:lower() 
    if key == "w" then -- i dont know how to do it for the up key, sorry
    animTrack:Play()
    end
end 
script.Parent.Parent:GetMouse().KeyDown:connect(onKeyDown)

make sure it is in a local script, in the player's backpack

0
you forgot to tell the game what "Humanoid" is.:local Humanoid = game.Players.LocalPlayer.Character.Humanoid Thelegendofbrio13 0 — 5y
Ad

Answer this question