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.
local Player = game.Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded:wait() local Humanoid = Character:waitForChild("Humanoid") local Animation = workspace:waitForChild("Animation") local AnimationTrack = Humanoid:LoadAnimation(Animation) local UIS = game:getService("UserInputService") UIS.InputBegan:connect(function(InputObject, gameProcessedEvent) if not gameProcessedEvent then if InputObject.KeyCode == Enum.KeyCode.P then AnimationTrack:Play() end end 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?
local Player = game.Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded:wait() local Humanoid = Character:waitForChild("Humanoid") local Animation = Instance.new("Animation") --creates new animation object Animation.AnimationId = "rbxassetid://Your Animation" --sets the id local AnimationTrack = Humanoid:LoadAnimation(Animation) -- loads the animation local UIS = game:getService("UserInputService") UIS.InputBegan:connect(function(InputObject, gameProcessedEvent) if not gameProcessedEvent then if InputObject.KeyCode == Enum.KeyCode.P then AnimationTrack:Play() --it should work now end end end)
If it works please accept and thanks for asking -_^ ~KiHeros