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!
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.
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
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)