I press the l key and nothing happens, why is this? The script is in the starter pack and it has an animation with the correct code in it. I can't figure out why this doesn't work, and i'm not very good with scripts.
Why does this animation script when i press a key not working?
4 answers
It does not work due to the fact that KeyDown is deprecated. Instead, use ContextActionService. And as previous answers said, you defined the player as LocalPlayer but used player.
function playAnimation()
local plr = game:GetService('Players').LocalPlayer
local anim = script.Animation
local track = plr.Character.Humanoid:LoadAnimation(anim)
track:Play()
end
game:GetService('ContextActionService'):BindAction(
"PlayAnim",
playAnimation,
false,
Enum.KeyCode.One
)
This will work since it has no deprecated code.
It doesn't work cause you defined your player as LocalPlayer and later used player
What you can do to fix it is just to change every place where you have player in your script to LocalPlayer
1 comment
Still doesn't work.
Basically what they are both saying is that you forgot to put a space between local and player, lol.
1 comment
Still nothing .-.
It's because you declared your variable as LocalPlayer but are trying to reference it by typing player. In fact, Lua automatically will show a blue line under variables it considers undefined (The blue lines under player in your screenshot).
The fixed code would change LocalPlayer to player or player to LocalPlayer:
wait(2)
player = game.Players.LocalPlayer
local Mouse = player:GetMouse()
Anim = script.Animation
Mouse.Keydown:connect(function(key)
if key == '1' then
a = player.Character.Humanoid:LoadAnimation(Anim)
a:Play()
end
end)
Also, KeyDown is deprecated, meaning there is a better newer different version of it you should use instead. If you are comfortable with keydown thats fine, but it's better to use UserInputService or ContextActionService. Check out this page on the wiki:
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
Even though KeyDown is deprecated, it still works...
Not for me. I tried it just for fun and it says 'KeyDown' is not a valid member of Mouse