Skip to content

Input

System · Input · server and client scripts

Input reads the local player's keyboard, mouse, gamepad, touch, and VR controller input and sets the cursor and UI selection. It works in client scripts only.

Every pressable input has one InputName string: keys such as "E", "Enter", "LeftShift", and "ArrowUp", mouse buttons ("MouseLeft", "MouseRight", "MouseMiddle", "MouseX1", "MouseX2"), wheel turns ("WheelUp", "WheelDown", "WheelLeft", "WheelRight"), gamepad buttons ("ButtonA", "LeftTrigger", "RightTrigger"), VR buttons ("VRTriggerRight"), and "Touch". Analog thumbsticks have no InputName; read them with Input.Stick or bind them with InputBinding.Stick (see Input entities).

Opening the escape menu or a host modal releases every held input: WasReleased returns true and Released(input, false) fires on that frame. An input still held when the menu closes stays up until the player releases and presses it again.

IsDown

FunctionClient only
IsDown(input: InputName) -> boolean

IsDown returns true while the input named input is held down, unless the escape menu, engine UI, or a Sink input context took it.

Example

-- Client script.
function Update(dt: number)
    if Input.IsDown("MouseRight") then
        print("aiming")
    end
end
Errors (1)
Error When
IsDown can only be called from a client script Called from a server script.

WasPressed

FunctionClient only
WasPressed(input: InputName) -> boolean

WasPressed returns true on the frame the input named input goes down, and false after. Wheel turns and taps within one frame return true on that frame.

Example

-- Client script.
function Update(dt: number)
    if Input.WasPressed("E") then
        print("use")
    end
end
Errors (1)
Error When
WasPressed can only be called from a client script Called from a server script.

WasReleased

FunctionClient only
WasReleased(input: InputName) -> boolean

WasReleased returns true on the frame the input named input goes up, or on the frame the escape menu or a Sink context starts taking it.

Example

-- Client script.
function Update(dt: number)
    if Input.WasReleased("Space") then
        print("jump released")
    end
end
Errors (1)
Error When
WasReleased can only be called from a client script Called from a server script.

GetHeld

FunctionClient only
GetHeld() -> {InputName}

GetHeld returns the InputName list of inputs currently held down and not taken by the escape menu, engine UI, or a Sink context.

Example

-- Client script.
function Update(dt: number)
    local held = Input.GetHeld()
    if #held > 1 then
        print("chord: " .. table.concat(held, " + "))
    end
end
Errors (1)
Error When
GetHeld can only be called from a client script Called from a server script.

Pressed

EventClient onlyRead only
Pressed: Signal<(input: InputName, processed: boolean) -> ()>

Pressed fires with (input, processed) when an input goes down. processed is true when the escape menu, a host modal, a focused text box, or engine UI took the press. Inputs taken by a Sink context do not fire Pressed.

Example

-- Client script.
Input.Pressed:Connect(function(input: InputName, processed: boolean)
    if not processed and input == "WheelUp" then
        print("next weapon")
    end
end)
Errors (1)
Error When
Pressed can only be written from a client script Written from a server script.

Released

EventClient onlyRead only
Released: Signal<(input: InputName, processed: boolean) -> ()>

Released fires with (input, processed) when an input goes up, with the same processed value as its Pressed. Inputs taken by a Sink context do not fire Released.

Example

-- Client script.
Input.Released:Connect(function(input: InputName, processed: boolean)
    if not processed and input == "MouseLeft" then
        print("released")
    end
end)
Errors (1)
Error When
Released can only be written from a client script Written from a server script.

MoveCharacter

PropertyClient only
MoveCharacter: boolean

MoveCharacter controls whether built-in character movement and jump controls read player input. Set it to false when a custom vehicle, menu, or text capture takes over movement.

Default true

Errors (1)
Error When
MoveCharacter can only be written from a client script Written from a server script.

Capture

CaptureText

PropertyClient only
CaptureText: boolean

CaptureText turns on the operating system's text input when true and sends committed UTF-8 text to TextInput while the escape menu and console are closed. While a text box has focus, the text box receives the typed text and TextInput does not fire.

Default false

Errors (1)
Error When
CaptureText can only be written from a client script Written from a server script.

TextCursor

PropertyClient only
TextCursor: Vector2?

TextCursor sets the IME candidate window position in UI points from the top-left corner of the game view while CaptureText is true, or nil to clear it. A focused text box sets its own IME position while it has focus.

Default nil

Example

-- Client script.
Input.CaptureText = true
Input.TextCursor = Vector2.new(120, 48)
Errors (1)
Error When
TextCursor can only be written from a client script Written from a server script.

TextInput

EventClient onlyRead only
TextInput: Signal<(text: string) -> ()>

TextInput fires with text, the UTF-8 text the player committed since the last frame, while CaptureText is true.

Example

-- Client script.
Input.MoveCharacter = false
Input.CaptureText = true
local typed = ""
Input.TextInput:Connect(function(text: string)
    typed ..= text
    print(typed)
end)
Errors (1)
Error When
TextInput can only be written from a client script Written from a server script.

Cursor

MouseCursor

PropertyClient only
MouseCursor: string

MouseCursor is the cursor shape over the 3D world and over UI elements whose Cursor is "Auto", using a string cursor name such as "Auto", "Crosshair", "Pointer", or "Hidden".

Default "Auto"

Example

-- Client script.
Input.MouseCursor = "Crosshair"
Errors (1)
Error When
MouseCursor can only be written from a client script Written from a server script.

SetCustomCursor

FunctionClient only
SetCustomCursor(shape: CustomCursorShape, image: string?, hotspot: Vector2?) -> ()

SetCustomCursor shows an image in place of one cursor shape (other than "Auto" and "Hidden"), with an optional click point in image pixels.

Example

-- Client script.
local SWORD_CURSOR = "72057594037927978"
Input.SetCustomCursor("Arrow", SWORD_CURSOR, Vector2.new(2, 2))
task.wait(10)
Input.SetCustomCursor("Arrow", nil)
Errors (1)
Error When
SetCustomCursor can only be called from a client script Called from a server script.

Device

PreferredInput

PropertyClient onlyRead only
PreferredInput: string

PreferredInput is the device type the player used last ("KeyboardAndMouse", "Gamepad", "Touch", or "VR").

Default "KeyboardAndMouse"

Errors (1)
Error When
PreferredInput can only be written from a client script Written from a server script.

PreferredInputChanged

EventClient onlyRead only
PreferredInputChanged: Signal<(device: InputDevice) -> ()>

PreferredInputChanged fires with the new PreferredInput when the player switches between keyboard and mouse, gamepad, touch, and VR.

Example

-- Client script.
Input.PreferredInputChanged:Connect(function(device)
    print(device == "Touch")
end)
Errors (1)
Error When
PreferredInputChanged can only be written from a client script Written from a server script.

Gamepad

Stick

FunctionClient only
Stick(name: InputStick, deadzone: number?) -> Vector2

Stick returns the 2D deflection of "LeftStick" or "RightStick" as a Vector2 with radial deadzone applied. deadzone is a number in 0..0.95 (default 0.2). Returns Vector2.Zero while the escape menu is open or a Sink context takes the stick.

Example

-- Client script.
function Update(dt: number)
    local move = Input.Stick("LeftStick")
    local aim = Input.Stick("RightStick", 0.3)
    if move.Magnitude > 0 or aim.Magnitude > 0 then
        print(move.X, move.Y, aim.X, aim.Y)
    end
end
Errors (1)
Error When
Stick can only be called from a client script Called from a server script.

Trigger

FunctionClient only
Trigger(name: InputTrigger, deadzone: number?) -> number

Trigger returns the analog pull in 0..1 of "LeftTrigger" or "RightTrigger" after deadzone rescaling. deadzone is a number in 0..0.95 (default 0.1). Returns 0 while the escape menu is open or a Sink context takes the trigger.

Example

-- Client script.
function Update(dt: number)
    local throttle = Input.Trigger("RightTrigger")
    if throttle > 0 then
        print(throttle)
    end
end
Errors (1)
Error When
Trigger can only be called from a client script Called from a server script.

Vibrate

FunctionClient only
Vibrate(low: number, high: number, seconds: number) -> ()

Vibrate pulses the last active gamepad's low-frequency and high-frequency motors with (low, high, seconds). low and high are in 0..1, and seconds is in 0..60. Opening the escape menu or losing window focus stops rumble.

Example

-- Client script.
Input.Vibrate(0.5, 0.25, 0.2)
Errors (1)
Error When
Vibrate can only be called from a client script Called from a server script.

Pointer

Selected

PropertyClient only
Selected: Entity?

Selected is the UI element that has the gamepad and keyboard selection, or nil.

Default nil

Example

-- Client script.
local screen = World.Spawn({ UIRoot = true })
screen.Parent = World.Viewport.Screen
local play = World.Spawn({
    Box = {},
    Panel = {},
    UITextSource = { Text = "Play" },
    Button = true,
})
play.Parent = screen
play:On(Component.Button.Clicked, function()
    print("play")
end)
Input.Selected = play
Errors (1)
Error When
Selected can only be written from a client script Written from a server script.

MouseBehavior

PropertyClient only
MouseBehavior: string

MouseBehavior is "Default" or "LockCenter".

Default "Default"

Errors (1)
Error When
MouseBehavior can only be written from a client script Written from a server script.

MousePosition

PropertyClient onlyRead only
MousePosition: Vector2

MousePosition is the cursor position in UI points from the top-left corner of the game view.

Errors (1)
Error When
MousePosition can only be written from a client script Written from a server script.

MouseDelta

PropertyClient onlyRead only
MouseDelta: Vector2

MouseDelta is the cursor movement since the last script update, in UI points.

Errors (1)
Error When
MouseDelta can only be written from a client script Written from a server script.

LookDelta

PropertyClient onlyRead only
LookDelta: Vector2

LookDelta is the mouse movement since the last script update, in the units the built-in camera turns by.

Errors (1)
Error When
LookDelta can only be written from a client script Written from a server script.

Scroll

PropertyClient onlyRead only
Scroll: number

Scroll is the mouse wheel movement since the last script update, positive up.

Errors (1)
Error When
Scroll can only be written from a client script Written from a server script.

RotationType

PropertyClient only
RotationType: string

RotationType is "MovementRelative" or "CameraRelative", controlling whether the character turns toward its movement direction or faces the camera's horizontal direction.

Default "MovementRelative"

Errors (1)
Error When
RotationType can only be written from a client script Written from a server script.

Touch

Touches

FunctionClient only
Touches() -> {Touch}

Touches returns the active unprocessed touches ordered by Id, up to five simultaneous fingers. Each Touch has Id, Position, StartPosition, and Delta in UI points.

Touches do not emulate mouse buttons or move MousePosition. "Touch" is held while any unprocessed finger is down.

Example

-- Client script.
function Update(dt: number)
    for _, touch in Input.Touches() do
        print(touch.Id, touch.Position.X, touch.Position.Y)
    end
end
Errors (1)
Error When
Touches can only be called from a client script Called from a server script.

TouchBegan

EventClient onlyRead only
TouchBegan: Signal<(touch: Touch, processed: boolean) -> ()>

TouchBegan fires with (touch, processed) when a finger touches down. processed is true when engine UI or a Button took the touch.

Example

-- Client script.
Input.TouchBegan:Connect(function(touch: Touch, processed: boolean)
    if not processed then
        print(touch.Id, touch.StartPosition.X, touch.StartPosition.Y)
    end
end)
Errors (1)
Error When
TouchBegan can only be written from a client script Written from a server script.

TouchMoved

EventClient onlyRead only
TouchMoved: Signal<(touch: Touch, processed: boolean) -> ()>

TouchMoved fires once per frame with (touch, processed) for each active finger that moved, with touch.Delta equal to the frame's movement.

Example

-- Client script.
Input.TouchMoved:Connect(function(touch: Touch, processed: boolean)
    if not processed then
        print(touch.Id, touch.Delta.X, touch.Delta.Y)
    end
end)
Errors (1)
Error When
TouchMoved can only be written from a client script Written from a server script.

TouchEnded

EventClient onlyRead only
TouchEnded: Signal<(touch: Touch, processed: boolean) -> ()>

TouchEnded fires with (touch, processed) when a finger lifts, cancels, or is released by the escape menu opening.

Example

-- Client script.
Input.TouchEnded:Connect(function(touch: Touch, processed: boolean)
    print(touch.Id, processed)
end)
Errors (1)
Error When
TouchEnded can only be written from a client script Written from a server script.