How do I enable my game only for VR players?

So, today I started developing a game called “VR Minigames” and the game has minigames and sandbox mode (If you missed the post, here is a link: What type of VR game should I do?). But Idk how to enable the game only for VR players and kick the non-vr players. Can someone help me? It’s highly appreciated if you do.

Moved the topic to scripting support and removed the scripting tag as this is about scripting.


All you can really do ingame is kick the players locally after they join if UserInputService.VREnabled is false. Making a game VR-only from the website isn’t practical at this point since the website has no way of knowing if you have a VR headset active.

1 Like

I mean, maybe like a 5 second count if they don’t have it on.

You could do this, like what nexusavenger said.

local input = game:GetService("UserInputService")
game.Players.PlayerAdded:Connect(function(player)
    if not input.VREnabled then
        player:Kick("You don't have VR enabled")
        else
        print("You are allowed in, VR is enabled")
    end
end)

Should the script be in StarterPlayerScripts?

Yes, try there.

Local or Module? (30 characters)

It should be a LocalScript. In order for a ModuleScript to run, it’d need to be required by a LocalScript.

On another note:
The script is a bit incorrect, that will not do what you want it to do, or expect to do.
You are connecting to a PlayerAdded event, in a LocalScript. This means PlayerAdded will not run for LocalPlayer, due to the fact that the player has already joined the game when the script itself starts actually starts. It would do the check only when another player joins the game.

What you are looking for would look something more like this:

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

local Client = Players.LocalPlayer
if not UserInputService.VREnabled then
	Client:Kick("VR is not enabled")
end
script:Destroy()
1 Like