VRService

Show Deprecated
Not Creatable
Service

VRService is responsible for handling interactions between Roblox and Virtual Reality (VR). Its methods, properties, and events help you provide the best experience for end users seeking to experience Roblox on VR devices.

See VR Guidelines for more information on publishing an experience for VR devices.

Code Samples

VRService

local VRService = game:GetService("VRService")
local part = workspace.Part
local handOffset = VRService:GetUserCFrame(Enum.UserCFrame.LeftHand)
-- Account for headscale
handOffset = handOffset.Rotation + handOffset.Position * workspace.CurrentCamera.HeadScale
part.CFrame = workspace.CurrentCamera.CFrame * handOffset

Summary

Properties

Methods

Properties

AutomaticScaling

Read Parallel

When set to Enum.VRScaling.World, Camera.HeadScale adjusts so that the scale of the world is seen from the avatar's perspective. A player with a small avatar will perceive the objects around them as larger than a player with a large avatar will.

AvatarGestures

Read Parallel

When set to true, a VR player will be able to animate their hands and head using their controllers and headset.

This property must be set on the server.

Read Parallel

FadeOutViewOnCollision

Read Parallel

When true, a VR player's view fades to black when their head collides with an object. This property prevents players from being able to see through walls while in VR. The default value is true.

GuiInputUserCFrame

Not Replicated
Read Parallel

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

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

Code Samples

VRService.GuiInputUserCFrame

local VRService = game:GetService("VRService")
if VRService.VREnabled then
print(VRService.GuiInputUserCFrame.Name)
else
print("No VR device detected!")
end
Read Parallel

ThirdPersonFollowCamEnabled

Read Only
Not Replicated
Read Parallel

VREnabled

Read Only
Not Replicated
Read Parallel

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 methods such as UserInputService:GetUserCFrame(). You can also react to VR device movement using the UserInputService.UserCFrameChanged event.


local UserInputService = game:GetService("UserInputService")
local isUsingVR = UserInputService.VREnabled
if isUsingVR then
print("User is using a VR headset!")
else
print("User is not using a VR headset!")
end

This property can only be used in a LocalScript.

See Also

Code Samples

VR Head Tracking

local VRService = game:GetService("VRService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.CharacterAdded:Wait()
local head = character:WaitForChild("Head")
local function TrackHead(inputType, value)
if inputType == Enum.UserCFrame.Head then
head.CFrame = value
end
end
if VRService.VREnabled then
-- Set the initial CFrame
head.CFrame = VRService:GetUserCFrame(Enum.UserCFrame.Head)
-- Track VR headset movement and mirror for character's head
VRService.UserCFrameChanged:Connect(TrackHead)
end

Methods

GetTouchpadMode

This method returns the Enum.VRTouchpadMode indicating the mode of a specified Enum.VRTouchpad. The returned mode indicates how the user interacts with their touchpad to play the game.

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

This method will only work when used in a LocalScript.

Parameters

The specified VRTouchpad.


Returns

The mode of the specified VRTouchpad.

Code Samples

VRService:GetTouchpadMode

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

GetUserCFrame

This method returns a CFrame describing the position and orientation of a specified virtual reality (VR) device as an offset from a point in real world space. This method should be used when implementing VR compatibility into a game to obtain and track the movement of a connected VR device.

By using the method, developers 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.

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

This method will only work when used in a LocalScript.

Parameters

The specified UserCFrame.


Returns

Code Samples

VRService:GetUserCFrame

local Workspace = game:GetService("Workspace")
local VRService = game:GetService("VRService")
local camera = Workspace.CurrentCamera
local part = script.Parent.Part
local handOffset = VRService:GetUserCFrame(Enum.UserCFrame.LeftHand)
-- Account for headscale
handOffset = handOffset.Rotation + handOffset.Position * camera.HeadScale
part.CFrame = camera.CFrame * handOffset

GetUserCFrameEnabled

This method returns true if the specified Enum.UserCFrame virtual reality device (VR) is available to be listened to. It can be used to determine whether a specified VR device, such as Enum.UserCFrame.Head, is connected to the user's game.

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

This method 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

local VRService = game:GetService("VRService")
local isEnabled = VRService:GetUserCFrameEnabled(Enum.UserCFrame.Head)
if isEnabled then
print("VR device is enabled!")
else
print("VR device is disabled!")
end

RecenterUserHeadCFrame

void

This method re-centers the CFrame of the user's head to the current location of the VR headset being worn by the user. It 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 behaves identically to UserInputService:RecenterUserHeadCFrame().

This method will only work when used in a LocalScript.


Returns

void

Code Samples

VRService:RecenterUserHeadCFrame

local VRService = game:GetService("VRService")
VRService:RecenterUserHeadCFrame()

RequestNavigation

void

This method requests navigation to the specified CFrame using the specified Enum.UserCFrame as the origin for the visualizer parabola. It 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.

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

This method will only work when used in a LocalScript.

Parameters

cframe: CFrame

The specified CFrame coordinates.

inputUserCFrame: Enum.UserCFrame

The VR device for which the navigation is requested.


Returns

void

Code Samples

VRService:RequestNavigation

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

SetTouchpadMode

void

This method sets the mode of the specified Enum.VRTouchpad to the specified Enum.VRTouchpadMode. It can be used to change the user's virtual reality (VR) touchpad mode so that the user interacts with the game differently using the touchpad.

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

This method 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

void

Code Samples

VRService:SetTouchpadMode

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

Events

This event fires when navigation is requested from VRService for a specified Enum.UserCFrame VR device. It fires with a CFrame coordinate and the specified Enum.UserCFrame indicating the device requesting the navigation.

This event can be used alongside UserInputService service events and methods.

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

Parameters

cframe: CFrame

The requested CFrame coordinates.

inputUserCFrame: Enum.UserCFrame

Indicates the VR device for which navigation is requested.


Code Samples

VRService.NavigationRequested

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

TouchpadModeChanged

This event fires if the Enum.VRTouchpadMode of a Enum.VRTouchpad is changed. You can use this event to track the states of VR touchpads connected via the user's client.

This event can be used alongside UserInputService service events and methods.

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

Parameters

The touchpad that changed mode.

The new mode.


Code Samples

VRService.TouchpadModeChanged

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

UserCFrameChanged

This event fires when a Enum.UserCFrame is changed, for instance when the user moves a connected VR device. It can be used alongside GetUserCFrame() to track the CFrame coordinates of a VR device, and when it changes/moves. It can also be used alongside UserInputService service events and methods.

Since this 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

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

UserCFrameEnabled

This event fires when a Enum.UserCFrame is enabled or disabled. It can be used alongside GetUserCFrameEnabled() to track whether a specified UserCFrame is enabled, and when its state changes. It can also be used alongside UserInputService service events and methods.

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

Parameters

The UserCFrame getting enabled or disabled.

enabled: bool

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


Code Samples

VRService.UserCFrameEnabled

local VRService = game:GetService("VRService")
VRService.UserCFrameEnabled:Connect(function(type, enabled)
if enabled then
print(type.Name .. " got enabled!")
else
print(type.Name .. " got disabled!")
end
end)