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

How Do You Make This Script Work When You Press an Arrow Key?

How Do You Make This Script Work When You Press a Arrow Key? Script:

function OnKeyDown(key)
	if (key == '') then
	end
end

game.Players.LocalPlayer:GetMouse().KeyDown:connect(OnKeyDown)

Thank you!

1 comment

0

You can use string.byte(), but you need to get arrow key code.

1 answer

In a LocalScript:

local UIS = game:GetService("UserInputService") -- What the UIS is, is basically an ear for anything the Users do. Such as: Press a key, Type in chat AND MUCH MUCH MOREEE!~
UIS.InputBegan:connect(function(input) -- If UIS has been fired
	if input.UserInputType == Enum.UserInputType.Keyboard and input.UserInputState == Enum.UserInputState.Begin then -- If The user is using the keyboard, and Has pressed a key.
		if  input.Keycode == Enum.KeyCode.Down or input.Keycode == Enum.Keycode.Left or input.Keycode == Enum.Keycode.Right or input.Keycode == Enum.Keycode.Up then -- Checks for Left, Right, Up, or Down keys being pressed, if not, moves on.
			-- CODE HERE :)
		end	
	end
end)

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