here is what i have so far
local M = game.Players.LocalPlayer:GetMouse() HI = game.Players.LocalPlayer.PlayerGui.ScreenGui.TextButton:WaitForChild("intiger") Animation = script:WaitForChild("Animation") local player = game.Players.LocalPlayer hp = player.Character.Humanoid M.KeyDown:Connect(function(key) if key == "f" then local Animationtrack = hp:LoadAnimation(Animation) Animationtrack:Play() HI.Value = HI.Value + 1 end end)
UserInputService
is much better than KeyDown (since UserInputService can get inputs from game controllers and touchscreen).
--Must be done in a local script game:GetService("UserInputService").InputBegan:Connect(function(key) if key.KeyCode == Enum.KeyCode.F then print("F was pressed") end end)
Use this site if you want to see the Enum index for keycodes.
The reason why the animation may not be running is because Animations have different priorities dictating which animation be played over another. Here is a list of enums for AnimationPriority
. If you want an animation to be played, you should set its priority to something higher than the default animations (action is the highest priority). If an animation is played and another animation is played with the same priority, the first animation is stopped over the second one.
Also, make sure you identify the variable hp
inside of the event, not outside. In case the character respawns, it'll use the new humanoid.
local HI = game.Players.LocalPlayer.PlayerGui.ScreenGui.TextButton:WaitForChild("intiger") local Animation = script:WaitForChild("Animation") local player = game:GetService("Players").LocalPlayer game:GetService("UserInputService").InputBegan:Connect(function(key) if key.UserInputType == Enum.UserInputType.Keyboard then --Make sure it is a keyboard input if key.KeyCode == Enum.KeyCode.F then local humanoid = player.Character:FindFirstChild("Humanoid") if humanoid then --If humanoid exists local playAnim = humanoid:LoadAnimation(Animation) playAnim.Priority = Enum.AnimationPriority.Action --Highest priority animation playAnim:Play() HI.Value = HI.Value + 1 end end end end)
Change Enum...Action
to Enum...Core
if you want animations like walking, falling, jumping or swimming to override it.
Hope it helps!