VR-Only Experience

Hey Developers,

I’ve been getting into VR for Roblox, and I want to create an immersive VR Experience. For this experience, I don’t want non-VR players joining the experience, since it was originally intended for VR-Players.

If you have any code that will help, or suggestions, please let me know!

2 Likes

If you’re game is supposed to be free, then a local script, do this:

local VRService = game:GetService("VRService")

if VRService.VREnabled == true then
     --VR Functions
else
     game.Players.LocalPlayer:Kick("This is a VR only experience")
end

That will kick the player if they are not in VR.
I think the Kick function works on the Client, I don’t quite remember.

3 Likes

I have a question. What does the code you provided mean by VR Functions?

1 Like

I think they expected you just to put other code related to your game there. However, you could just do the following at the top of a script to achieve the same effect (based on their code).

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

local LocalPlayer = Players.LocalPlayer

if (not VRService.VREnabled) then
    return LocalPlayer:Kick("This is a VR only experience")
end
4 Likes

Thanks for the help! I appreciate it.

2 Likes

I have a question, is it possible to only show a certain GUI to VR Players only? The kick script is great, kudos to you, but a GUI that I have isn’t disabled and shows for non-VR Players.

This is the code I have, but isn’t working:

local Players = game:GetService("Players")
local vrService = game:GetService("VRService")
local gui = script.Parent -- i placed this script in the GUI but still isnt disabling when non-VR players join

local function onPlayerAdded(player)
	if vrService:GetUserCFrame(Enum.UserCFrame.Head) ~= nil then
		gui.Enabled = true
	else
		gui.Enabled = false
	end
end

Players.PlayerAdded:Connect(onPlayerAdded)

Put a LocalScript under the Gui with the following code:

local VRService = game:GetService("VRService")

local Gui = script.Parent
Gui.Enabled = false

if (not VRService.VREnabled) then
	Gui.Enabled = true
end

Thank you so much! You’ve been really helpful!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.