Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Whats wrong with this script?

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)

1 comment

0

Shouldnt be spaces. But it messed it up when i put the script in here.

1 answer

✓ Accepted answer

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.

1 comment

0

Thanks.

This discussion is preserved as it was. New answers, comments, and votes are closed.