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

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

Asked by 8 years ago

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!

0
You can use string.byte(), but you need to get arrow key code. Mokiros 135 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago

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)
Ad

Answer this question