Skip to content

VR

System · VR · server and client scripts

VR reads headset and motion controller poses, velocities, analog inputs, and session state on the local client, and queues controller haptics and play-space recentering. It works in client scripts only.

Enabled

PropertyClient onlyRead only
Enabled: boolean

Enabled is true while an XR session is active on this client.

Default false

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

SessionState

PropertyClient onlyRead only
SessionState: VRState

SessionState is the current lifecycle state of the XR session ("Off", "Idle", "Ready", "Synchronized", "Visible", "Focused", "Stopping", "LossPending", or "Exiting").

Default "Off"

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

HeadScale

PropertyClient only
HeadScale: number

HeadScale multiplies every position returned by Pose in units and scales stereo view separation around the play-space origin.

Default 1

Example

-- Client script.
VR.HeadScale = 2
local headPos = VR.Pose("Head")
print(headPos)
Errors (1)
Error When
HeadScale can only be written from a client script Written from a server script.

Pose

FunctionClient only
Pose(device: VRDevice) -> (Vector3, Rotation, boolean)

Pose returns the device position in play-space units, its orientation as a Rotation, and whether the device currently has a valid tracked pose.

Example

-- Client script.
function Update(dt: number)
    local pos, rot, tracked = VR.Pose("RightAim")
    if tracked then
        local forward = rot:Apply(Vector3.new(0, 0, -1))
        self.Position = pos + forward * 2
    end
end
Errors (1)
Error When
Pose can only be called from a client script Called from a server script.

Velocity

FunctionClient only
Velocity(device: VRDevice) -> Vector3?

Velocity returns the linear velocity of device in units per second, or nil when unavailable.

Example

-- Client script.
local v = VR.Velocity("RightHand")
if v then
    print(v)
end
Errors (1)
Error When
Velocity can only be called from a client script Called from a server script.

AngularVelocity

FunctionClient only
AngularVelocity(device: VRDevice) -> Vector3?

AngularVelocity returns the angular velocity of device in degrees per second, or nil when unavailable.

Example

-- Client script.
local w = VR.AngularVelocity("RightHand")
if w then
    print(w)
end
Errors (1)
Error When
AngularVelocity can only be called from a client script Called from a server script.

IsTracked

FunctionClient only
IsTracked(device: VRDevice) -> boolean

IsTracked returns true when device ("Head", "LeftHand", "RightHand", "LeftAim", or "RightAim") has a valid tracked pose this frame.

Example

-- Client script.
if VR.IsTracked("LeftHand") then
    print("left controller tracked")
end
Errors (1)
Error When
IsTracked can only be called from a client script Called from a server script.

Thumbstick

FunctionClient only
Thumbstick(hand: VRHand, deadzone: number?) -> Vector2

Thumbstick returns the 2D deflection of the controller thumbstick for hand ("Left" or "Right") as a Vector2.

Example

-- Client script.
function Update(dt: number)
    local stick = VR.Thumbstick("Left")
    if stick.Magnitude > 0.2 then
        print(stick.X, stick.Y)
    end
end
Errors (1)
Error When
Thumbstick can only be called from a client script Called from a server script.

Trigger

FunctionClient only
Trigger(hand: VRHand, deadzone: number?) -> number

Trigger returns the analog index trigger pull from 0 to 1 for hand.

Example

-- Client script.
function Update(dt: number)
    if VR.Trigger("Right") > 0.5 then
        print("firing")
    end
end
Errors (1)
Error When
Trigger can only be called from a client script Called from a server script.

Squeeze

FunctionClient only
Squeeze(hand: VRHand, deadzone: number?) -> number

Squeeze returns the analog grip squeeze from 0 to 1 for hand.

Example

-- Client script.
function Update(dt: number)
    if VR.Squeeze("Left") > 0.75 then
        print("gripping")
    end
end
Errors (1)
Error When
Squeeze can only be called from a client script Called from a server script.

Recenter

FunctionClient only
Recenter() -> ()

Recenter requests a play-space recenter so the player's current head position and horizontal yaw become the play-space origin facing -Z.

Example

-- Client script.
VR.Recenter()
Errors (1)
Error When
Recenter can only be called from a client script Called from a server script.

Vibrate

FunctionClient only
Vibrate(hand: VRHand, amplitude: number, seconds: number?, hertz: number?) -> ()

Vibrate queues a haptic vibration pulse on hand ("Left" or "Right").

Example

-- Client script.
VR.Vibrate("Right", 0.7, 0.08, 160)
Errors (1)
Error When
Vibrate can only be called from a client script Called from a server script.

StateChanged

EventClient onlyRead only
StateChanged: Signal<(state: VRState) -> ()>

StateChanged fires with the new SessionState string whenever the XR session changes state.

Example

-- Client script.
VR.StateChanged:Connect(function(state: string)
    if state == "Focused" then
        print("VR focused")
    end
end)
Errors (1)
Error When
StateChanged can only be written from a client script Written from a server script.

TrackingChanged

EventClient onlyRead only
TrackingChanged: Signal<(device: VRDevice, tracked: boolean) -> ()>

TrackingChanged fires with (device, tracked) whenever a VR device gains or loses pose tracking.

Example

-- Client script.
VR.TrackingChanged:Connect(function(device: string, tracked: boolean)
    print(device, tracked)
end)
Errors (1)
Error When
TrackingChanged can only be written from a client script Written from a server script.

Recentered

EventClient onlyRead only
Recentered: Signal<() -> ()>

Recentered fires when the play-space origin resets after Recenter or a headset system recenter.

Example

-- Client script.
VR.Recentered:Connect(function()
    print("play space recentered")
end)
Errors (1)
Error When
Recentered can only be written from a client script Written from a server script.