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.
https://gyazo.com/8e4569e28405b485b7f2627a19acb3c3
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
Basically what they are both saying is that you forgot to put a space between local and player, lol.
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:
http://wiki.roblox.com/index.php?title=Keyboard_input