I need when I press the L key to play an animation.
mouse.KeyDown:connect(function (key) key = string.lower(key) if string.byte(key) == l then running = true local Humanoid = game.Players.LocalPlayer.Character.Humanoid local Animation = script.Animation local Current = Humanoid:LoadAnimation(Animation) Current:Play() local keyConnection = mouse.KeyUp:connect(function(key) if string.byte(key) == l then running = false Current:Stop() end end)
I'll assume mouse
was defined earlier in the script.
Your problem is where you check the the key on lines 5 and 19. string.byte
returns the ascii value of the character. It's okay, I'm not sure what ascii is either. But this function basically just converts a character into a specific number that represents that character. In the case of L, that number is 76. You would therefore need to write
if string.byte(key) == 76 then
Although it's easier and much more readable to just compare it directly with the string.
if key == "l" then
But you shouldn't use KeyDown at all, since it is now deprecated. Use the UserInputService instead.