Basically, when a player presses p I want it to run a animation. When I press p, it doesn't run the animation. The animation is just a simple punching animaton.
01 | local Player = game.Players.LocalPlayer |
02 | local Character = Player.Character or Player.CharacterAdded:wait() |
03 | local Humanoid = Character:waitForChild( "Humanoid" ) |
04 |
05 | local Animation = workspace:waitForChild( "Animation" ) |
06 | local AnimationTrack = Humanoid:LoadAnimation(Animation) |
07 |
08 | local UIS = game:getService( "UserInputService" ) |
09 |
10 | UIS.InputBegan:connect( function (InputObject, gameProcessedEvent) |
11 | if not gameProcessedEvent then |
12 | if InputObject.KeyCode = = Enum.KeyCode.P then |
13 | AnimationTrack:Play() |
14 | end |
15 | end |
16 | end ) |
Maybe instead of getting an animation object in the workspace why not instance a new one and set the animation id in the script itself?
01 | local Player = game.Players.LocalPlayer |
02 | local Character = Player.Character or Player.CharacterAdded:wait() |
03 | local Humanoid = Character:waitForChild( "Humanoid" ) |
04 |
05 | local Animation = Instance.new( "Animation" ) --creates new animation object |
06 | Animation.AnimationId = "rbxassetid://Your Animation" --sets the id |
07 | local AnimationTrack = Humanoid:LoadAnimation(Animation) -- loads the animation |
08 |
09 | local UIS = game:getService( "UserInputService" ) |
10 |
11 | UIS.InputBegan:connect( function (InputObject, gameProcessedEvent) |
12 | if not gameProcessedEvent then |
13 | if InputObject.KeyCode = = Enum.KeyCode.P then |
14 | AnimationTrack:Play() --it should work now |
15 | end |
16 | end |
17 | end ) |
If it works please accept and thanks for asking -_^ ~KiHeros