VRService

Show Deprecated
Not Creatable
Service

The VRService is a service that is responsible for handling interactions between Roblox and Virtual Reality (VR). If you're interested in incorporating VR compatibility into your game, this is the service for you!

The primary purpose of this service is to allow for games to communication and cooperate with virtual reality decisions - such as VR headsets and controllers. It allows a LocalScript to perform different actions depending on the device, and in turn, helps developers provide the best experience for the end user seeking to experience Roblox using VR devices.

Some usages of this service include detecting whether a user has any connected VR devices, tracking when those devices move, and determining how those devices interact with the user's in-game controls. In order to detect user input, the service must look for a service event. For example, the service can detect VR device movement via events such as VRService.UserCFrameChanged.

Notes

  1. The UserInputService also contains several events and functions useful for enhancing a player's VR experience in your game.
  2. Since this service is client-side only, it will only work when used in a LocalScript. It will not work when used within a Script. Client-side only means that users in the game can only detect their own input - and not the input of other users.

Code Samples

VRService

1-- We must get the VRService before we can use it
2local VRService = game:GetService("VRService")
3
4-- A sample function providing one usage of UserCFrameChanged
5local function userCFrameChanged(typ, value)
6 print(typ.Name .. " changed. Updated Frame: " .. value)
7end
8
9VRService.UserCFrameChanged:Connect(userCFrameChanged)

Summary

Properties

Describes what UserCFrame is responsible for input in VR.

Describes whether the user is using a virtual reality device.

READ ONLY
NOT REPLICATED

Events

NavigationRequested(cframe: CFrame, inputUserCFrame: UserCFrame): RBXScriptSignal  

Fired when navigation is requested from the VRService.


Fires if the VRTouchpadMode of a VRTouchpad is changed.


Fired when a UserCFrame is changed.


Fires when a UserCFrame gets enabled or disabled.

Methods


Returns the VRTouchpadMode indicating the mode of a specified VRTouchpad.


Returns a CFrame describing the position & orientation of a specified virtual reality device.


Returns true if the specified UserCFrame is available to be listened to.


Recenters the CFrame to the current location of the VR headset being worn by the user.

RequestNavigation(cframe: CFrame, inputUserCFrame: UserCFrame): nil  

Requests navigation to the specified CFrame, using the specified UserCFrame as the origin for the visualizer parabola.


Sets the mode of the specified VRTouchpad to the specified VRTouchpadMode.

Properties

GuiInputUserCFrame

The GuiInputUserCFrame property describes what UserCFrame is responsible for input in VR. For instance, if a VR headset is responsible, the value of this property will be UserCFrame.Head.

To check if Roblox detects any VR devices, which would be responsible for input in VR, you can check the VRService.VREnabled property.

Since VRService only runs client-side, this property will only work when used in a LocalScript.

VREnabled

Read Only
Not Replicated

This property describes whether the user is using a virtual reality (VR) device.

If a VR device is enabled, you can interact with its location and movement through functions such as UserInputService:GetUserCFrame(). You can also react to VR device movement using the UserInputService.UserCFrameChanged event.


1local userInputService = game:GetService("UserInputService")
2
3local isUsingVR = userInputService.VREnabled
4if (isUsingVR) then
5 print("User is using a VR headset!")
6else
7 print("User is not using a VR headset!")
8end
9

As UserInputService isclient-side only, this property can only be used in a LocalScript.

See [this][1] article for VR best practices.

See also:

Events

The NavigationRequested event fires when navigation is requested from the VRService for a specified UserCFrame VR device.

This is fired with a CFrame coordinate and specified UserCFrame indicating the device requesting the navigation.

This VRService event can be used alongside UserInputService service events and functions.

Since the event fires locally, it can only be used in a LocalScript.

Parameters

cframe: CFrame

The requested CFrame coordinates.

inputUserCFrame: UserCFrame

Indicates the VR device for which navigation is requested.


Code Samples

VRService.NavigationRequested

1local VRService = game:GetService("VRService")
2
3VRService.TouchpadModeChanged:Connect(function(cframe, inputUserCFrame)
4 print(inputUserCFrame.Name .. " made request with CFrame: " .. cframe)
5end)

TouchpadModeChanged

The TouchpadModeChanged event fires if the VRTouchpadMode of a VRTouchpad is changed. This event indicates the VRTouchpad that changes, and its new state.

You can use this event to track the states of VRTouchpads connected via the user's client.

This VRService event can be used alongside UserInputService service events and functions.

Since the event fires locally, it can only be used in a LocalScript.

Parameters

The touchpad that changed mode.

The new mode.


Code Samples

VRService.TouchpadModeChanged

1local VRService = game:GetService("VRService")
2
3VRService.NavigationRequested:Connect(function(pad, mode)
4 print(pad.Name .. " Touchpad changed to state: " .. mode.Name)
5end)

UserCFrameChanged

The UserCFrameChanged even fires when a UserCFrame is changed. For instance, this event fires when the user moves a connected VR device.

This can be used alongside VRService:GetUserCFrame() to track the CFrame coordinates of a VR devices, and when it changes/moves. It can also be used alongside UserInputService service events and functions.

Since the event fires locally, it can only be used in a LocalScript.

Parameters

The type of VR device that changed.

value: CFrame

The updated CFrame coordinates of the VR device after the change.


Code Samples

VRService.UserCFrameChanged

1local VRService = game:GetService("VRService")
2
3VRService.UserCFrameChanged:Connect(function(userCFrameType, cframeValue)
4 print(userCFrameType.Name .. " changed. Updated Frame: " .. tostring(cframeValue))
5end)

UserCFrameEnabled

The UserCFrameEnabled event fires when a UserCFrame gets enabled or disabled.

This can be used alongside VRService:GetUserCFrameEnabled() to track whether a specified UserCFrame is enabled, and when its state changes. It can also be used alongside UserInputService service events and functions.

Since the event fires locally, it can only be used in a LocalScript.

Parameters

The UserCFrame getting enabled or disabled.

enabled: boolean

A boolean indicating whether the UserCFrame is enabled (true) or disabled (false).


Code Samples

VRService.UserCFrameEnabled

1local VRService = game:GetService("VRService")
2
3VRService.UserCFrameEnabled:Connect(function(type, enabled)
4 if enabled then
5 print(type.Name .. " got enabled!")
6 else
7 print(type.Name .. " got disabled!")
8 end
9end)

Methods

GetTouchpadMode

The GetTouchpadMode function returns the VRTouchpadMode indicating the mode of a specified VRTouchpad.

The returned mode indicates how the user interacts with their touchpad to play the game. For more information about the different types of modes, see the VRTouchpadMode page.

This can also be used alongside the several UserInputService VR functions and events.

Since VRService only runs client-side, this function will only work when used in a LocalScript.

Parameters

The specified VRTouchpad.


Returns

The mode of the specified VRTouchpad.

Code Samples

VRService:GetTouchpadMode

1local VRService = game:GetService("VRService")
2
3VRService:GetTouchpadMode(Enum.VRTouchpad.Left)

GetUserCFrame

The GetUserCFrame function returns a CFrame describing the position & orientation of a specified virtual reality (VR) device.

This function should be used when implementing VR compatibility into a game to obtain and track the movement of a connected VR device.

By using the function, players can implement features such as re-positioning the user's in-game character corresponding to the location of a connected VR device. This can be done by changing the CFrame of the user's in-game character to match the CFrame of the specified VR device using the UserCFrame enum and CFrame value arguments passed by the event.

The VRService service also provides an event VRService.UserCFrameChanged that automatically fires when the CFrame of connected VR device changes - so long it is used in a LocalScript.

This can also be used alongside the several UserInputService VR functions and events.

Since VRService only runs client-side, this function will only work when used in a LocalScript.

Parameters

The specified UserCFrame.


Returns

Code Samples

VRService:GetUserCFrame

1local VRService = game:GetService("VRService")
2
3local cf = VRService:GetUserCFrame(Enum.UserCFrame.Head)
4print("Enum.UserCFrame.Head:", cf)

GetUserCFrameEnabled

The GetUserCFrameEnabled function returns true if the specified UserCFrame virtual reality device (VR) is available to be listened to.

This can be used to determine whether a specified VR device, (e.g. UserCFrame.Head), is connected to the user's game. If the specified VR device is connected, is it enabled (true). Otherwise, it is disabled (false).

This can also be used alongside the several UserInputService VR functions and events.

Since VRService only runs client-side, this function will only work when used in a LocalScript.

Parameters

The specified type of VR device.


Returns

A boolean indicating whether the specified VR device is enabled (true) or disabled (false).

Code Samples

VRService:GetUserCFrameEnabled

1local VRService = game:GetService("VRService")
2
3local isEnabled = VRService:GetUserCFrameEnabled(Enum.UserCFrame.Head)
4if isEnabled then
5 print("VR device is enabled!")
6else
7 print("VR device is disabled!")
8end

RecenterUserHeadCFrame

The RecentUserHeadCFrame function recenters the CFrame of the user's head to the current location of the VR headset being worn by the user.

This function can be used to ensure that the user's in-game head is positioned according to the location of the user's VR headset.

This is similar to the UserInputService function, UserInputService:RecenterUserHeadCFrame().

Since VRServiceService only runs client-side, this function will only work when used in a LocalScript.


Returns

No return.

Code Samples

VRService:RecenterUserHeadCFrame

1local VRService = game:GetService("VRService")
2
3VRService:RecenterUserHeadCFrame()

RequestNavigation

The RequestNavigation function requests navigation to the specified CFrame, using the specified UserCFrame as the origin for the visualizer parabola.

This can be used to incorporate virtual reality (VR) into your game by providing a means to visualize a navigation path from the user's VR device to a destination.

The VRService has a similar event, VRService.NavigationRequested, used to detect such requests. This can also be used alongside the several UserInputService VR functions and events.

Since VRService only runs client-side, this function will only work when used in a LocalScript.

Parameters

cframe: CFrame

The specified CFrame coordinates.

inputUserCFrame: UserCFrame

The VR device for which the navigation is requested.


Returns

No return.

Code Samples

VRService:RequestNavigation

1local VRService = game:GetService("VRService")
2
3local destination = workspace:FindFirstChild("NavigationDestination")
4
5VRService:RequestNavigation(Enum.UserCFrame.Head, destination.CFrame)

SetTouchpadMode

The SetTouchpadMode function sets the mode of the specified VRTouchpad to the specified VRTouchpadMode.

This can be used to change the user's virtual reality (VR) touchpad mode so that the user interacts with the game different using the touchpad. For more information about the different types of modes, see the VRTouchpadMode page.

This can also be used alongside the several UserInputService VR functions and events.

Since VRService only runs client-side, this function will only work when used in a LocalScript.

Parameters

The specified VRTouchpad you want to set the mode of.

The mode you want to set the specified VRTouchpad to.


Returns

No return.

Code Samples

VRService:SetTouchpadMode

1local VRService = game:GetService("VRService")
2
3VRService:SetTouchpadMode(Enum.VRTouchpad.Left, Enum.VRTouchpadMode.Touch)