Im relatively new to scripting, So I need some help with this. I have the run animation ready.
Alright, the other answer was a little more complex then it needs to be.
First put the animation in a script. Then make the scripts code this:
game.Players.PlayerAdded:connect(function(player) local anim = player.Character.Humanoid:LoadAnimation(script.AnimName) local mouse = player:GetMouse() mouse.KeyDown:connect(function(key) local correctKey = "e" -- make whatever key you want if key == correctKey then anim:Play() end end) end)
Now, if you wanted to do a key that wasn't a letter then you'd need to find the key's number and then use this code:
if string.byte(key) == correctKey then
Opposed to:
if key == correctKey then
Try something like this?
local player = game.Players.LocalPlayer local humanoid = player.Character:WaitForChild("Humanoid") -- Wait for the Humanoid to exist local animation = Instance.new("Animation") animation.AnimationId = "http://www.roblox.com/Asset?ID=ASSETID" -- Replace ASSETID with the id of your animation local animTrack = Humanoid:LoadAnimation(animation) game:GetService("UserInputService").InputBegan:connect(function(inputObject) local keycode = 0 -- Replace 0 with the keycode of your key if inputObject.KeyCode == keycode then animTrack:Play() end end)
Find a list of keycodes on the wiki: http://wiki.roblox.com/index.php?title=API:Enum/KeyCode
You may have figured it out but this may be the best answer.
This is what I used: * UserInputService * Local Script
local uis = game:GetService("UserInputService") local plyr = game:GetService("Players").LocalPlayer local anim = Instance.new("Animation") anim.AnimationId = "rbxasset://" --Animation id here uis.InputBegan:connect(function(key, thing) local char = plyr:WaitForChild("Character") if key.KeyCode == Enum.KeyCode.A and thing then --Could be any letter(capitalized), Space, Escape, etc. local h = char:WaitForChild("Humanoid") h:LoadAnimation(anim):Play() --Custom animations run for 2 seconds(as of 2015) end end)
Hope it helps!
Enum works a little different from the string.byte()
. If you go here you can see in the first line, there is the key, the second there is the Value and the end is the description(which isn't added yet). So from this chart, 0 is actually the "Unknown" key.