So I have this keybind animation script. When I tested it out it wont work. What did I do wrong? Also I want the animation to play when key is pressed and stop when the key is unpressed. So, when you press and hold the key the animation will play and when you lift you finger from the key the animation will stop.
repeat wait() until game.Players.LocalPlayer.Character~=nil
local plr=game.Players.LocalPlayer
local chr=plr.Character
local hum=chr:WaitForChild("Humanoid")
local UserInput=game:GetService("UserInputService")
local crtAnimation
local normalSpeed=16
--put the keycode for each animation followed by the animation (animation must be inside the local script as well
local animationsList={
[Enum.KeyCode.LeftShift] = {hum:LoadAnimation(script:WaitForChild("Ready")),16}, -- the 16 and the 1 below are the speed of the player
[Enum.KeyCode.Q] = {hum:LoadAnimation(script:WaitForChild("Sit")),16},
}
local function StopAllAnims()
for _,v in pairs(animationsList) do
if crtAnimation~=v[1] and v[1].IsPlaying then v[1]:Stop() end
end
end
UserInput.InputBegan:connect(function(input)
if animationsList[input.KeyCode] ~= nil and UserInput:GetFocusedTextBox()==nil then
if animationsList[input.KeyCode][1] ~= crtAnimation then
crtAnimation=animationsList[input.KeyCode][1]
hum.WalkSpeed=animationsList[input.KeyCode][2]
StopAllAnims()
crtAnimation:Play()
else
hum.WalkSpeed=normalSpeed
crtAnimation=nil
StopAllAnims()
end
end
end)
