Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I trigger an animation on key hit?

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!

1 comment

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

1 answer

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

1 comment

0

you forgot to tell the game what "Humanoid" is.:local Humanoid = game.Players.LocalPlayer.Character.Humanoid

This discussion is preserved as it was. New answers, comments, and votes are closed.