This item is not replicated across Roblox’s server/client boundary.
This property can only be read from. Attempting to write to it will cause an error.
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 theUserInputService/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
UserInputService isclient-side only, this property can only be used in a
See this article for VR best practices.
VR Head Tracking
This example demonstrates how to implement a head tracking script that mirrors the movement of a virtual reality (VR) headset (the user’s actual head) to their in-game
The example first check if the user is using a VR device by checking the value of the
UserInputService/VREnabled|VREnabled property. This example only works if the user is using a VR headset.
To determine the initial
DataType/CFrame of the character’s head, the code sample calls
UserInputService/GetUserCFrame|GetUserCFrame and passes
Enum/UserCFrame|Enum.UserCFrame.Head as the argument.
To update the head’s CFrame whenever the user’s VR headset moves, the example connects the
UserInputService/UserCFrameChanged event to the TrackHead() function. When the event fires to indicate that a VR device moved, TrackHead() checks if the headset moved. If the headset moved, the function updates the CFrame of the character’s head to the
DataType/CFrame value provided as an argument.
As the UserCFrame enum also tracks VR left and right hand devices, the concept of VR device tracking can be expanded to other character bodyparts.
In order for the example to work as expected, it must be placed in a
local UserInputService = game:GetService("UserInputService") 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 UserInputService.VREnabled then -- Set the inital CFrame head.CFrame = UserInputService:GetUserCFrame(Enum.UserCFrame.Head) -- Track VR headset movement and mirror for character's head UserInputService.UserCFrameChanged:Connect(TrackHead) end