I have made an animation but I don't know how to make it play when a key is pressed this is just for one of my games. The game is non Filtering Enabled so don't worry about remotes and stuff.
http://wiki.roblox.com/index.php?title=API:Class/Humanoid/LoadAnimation Try this. When a key is pressed, load the animation into the humanoid and play it.
You can use the UserInputService to detect a key pressed then load the animation like this, it also doesn't matter if its Filtering Enabled or not.
01 | local p = game.Players.LocalPlayer |
02 | local animation = Instance.new( "Animation" ) |
03 | animation.AnimationId = "http://www.roblox.com/Asset?ID=id goes here" |
04 |
05 | local UIS = game:GetService( "UserInputService" ) |
06 |
07 | UIS.InputBegan:Connect( function (input, gameProcessedEvent) |
08 | local KeyCode = input.KeyCode |
09 | if not gameProcessedEvent then |
10 |
11 | if KeyCode = = Enum.KeyCode.E then -- Change E to any key you want |
12 | local animTrack = p.Character.Humanoid:LoadAnimation(animation) |
13 | animTrack:Play() |
14 |
15 | end |
16 | end |
17 | end ) |
Marked as Duplicate by Goulstem
This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.
Why was this question closed?