Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Whats wrong with this script?

Asked by 8 years ago

Please provide more explanation in your question. If you explain exactly what you are trying to accomplish, it will be much easier to answer your question correctly.

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)
0
Shouldnt be spaces. But it messed it up when i put the script in here. Lazynathaniel 10 — 8y

1 answer

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
8 years ago

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.

0
Thanks. Lazynathaniel 10 — 8y
Ad

Answer this question