Custom head script isnt working?

i have a script to detect if a player is in vr and it works good but the part that isnt working is the change head part of the script

game.Players.PlayerAdded:Connect(function(player)
	local char = player.Character
local userInputService = game:GetService("UserInputService")
local isUsingVR = userInputService.VREnabled
	if (isUsingVR) then
		print("VR Player!")
		char.Head.Mesh.MeshID = "https://assetdelivery.roblox.com/v1/asset/?id=9900352066"
		char.Head.Mesh.TextureID = "rbxassetid://9900377131"
		player.Character.HumanoidRootPart.Position = workspace.VRPlrSpawn
else
		print("Non VR Player")
		player.Character.HumanoidRootPart.Position = workspace.NonVRPlrSpawn
	end
end)

also i have the script in server script service idk if that matters though

Any errors in the output? also, i think roblox character heads use a specialmesh instead (maybe)

1 Like

the errors say ServerScriptService.VRCheck:12: attempt to index nil with ‘HumanoidRootPart’
and the name of the mesh is “mesh” so i dont think thats an issue

This means the character wasn’t added yet, change this

local char = player.Character

To

local char = player.Character or player.CharacterAdded:Wait()
1 Like

that fixed the issue, thank you! but do you know how i can make it so the player teleports there whenever they die?

1 Like

You can set the player SpawnPoint to that part, it’s a property of the player, i don’t remember its name tho

1 Like

couldnt i use humanoid.Died and then tp the player to that part when they respawn?

Oh right, that’s correct, better than mine as well!

1 Like

how do you think i could go about this? probably some thing like

game.Players.PlayerAdded:Connect(function(player)
	local char = player.Character or player.CharacterAdded:Wait()
	local hum = char:WaitForChild("Humanoid")
local userInputService = game:GetService("UserInputService")
local isUsingVR = userInputService.VREnabled
	if (isUsingVR) then
		print("VR Player!")
		char.Head.Mesh.MeshID = "https://assetdelivery.roblox.com/v1/asset/?id=9900352066"
		char.Head.Mesh.TextureID = "rbxassetid://9900377131"
		player.Character.HumanoidRootPart.Position = workspace.VRPlrSpawn
else
		print("Non VR Player")
		player.Character.HumanoidRootPart.Position = workspace.NonVRPlrSpawn.Position
		hum.Died:Connect(function()
			wait(2.1) -- respawn time in players properties
			char.HumanoidRootPart.Position = workspace.NonVRPlrSpawn.Position
			
		end)
	end
end)

Do this, I removed the one you made.

game.Players.PlayerAdded:Connect(function(player)
	local char = player.Character or player.CharacterAdded:Wait()

	local hum = char:WaitForChild("Humanoid")
local userInputService = game:GetService("UserInputService")
local isUsingVR = userInputService.VREnabled
	char.Humanoid.Died:Connect(function()
		wait(3) -- change 3 to the wait time
		if isUsingVR then
			player.Character.HumanoidRootPart.Position = workspace.VRPlrSpawn
		else
			player.Character.HumanoidRootPart.Position = workspace.NonVRPlrSpawn.Position
		end
	end) 
	if (isUsingVR) then
		print("VR Player!")
		char.Head.Mesh.MeshID = "https://assetdelivery.roblox.com/v1/asset/?id=9900352066"
		char.Head.Mesh.TextureID = "rbxassetid://9900377131"
		player.Character.HumanoidRootPart.Position = workspace.VRPlrSpawn
else
		print("Non VR Player")
		player.Character.HumanoidRootPart.Position = workspace.NonVRPlrSpawn.Position
	end
end)
1 Like

no errors but it didnt work anything else i can do?

I forgot to add a delay, after the died function add a delay until the player respawns, the respawns time is a property in game.Players take That time and add 0.1 to it and have that as the delay

1 Like

Put the solution as the script, just to make more sense, I edited it.

i know we already solved this but i was wondering, since youre like the only one who understands what im doing do you think i can make it so the vr player is in a specific spot with this intermission system?

--Thanks for using this script
--This script is made by Joriangames/Problox Studio Scripts
--Want to know how to use this? Watch my tutorial: https://youtu.be/kUqQhNT3hUE
local maps = game:GetService("ServerStorage").Maps:GetChildren()
local Title = game.StarterGui.MapSelector.Title
local spawns = game.Workspace.Spawns:GetChildren()
local status = game.ReplicatedStorage.Status
ti = 0

while true do
	ti = 10
	repeat
		ti = ti -1
		status.Value = "Intermission "..ti
		wait(1)
	until ti == 0
	
	local randomMap = maps[math.random(1, #maps)]
	randomMap:Clone().Parent = workspace
	current = randomMap.Name
	
	status.Value = "Chosen game is "..randomMap.Name
	wait(5)
	status.Value = "Loading game!"
	wait(3)
	status.Value = "Starting game!"
	wait(2)
	local plrs = game.Players:GetChildren()
	
	for i = 1, #plrs do
		local randomSpawn = spawns[math.random(1, #spawns)]
		plrs[i].Character.HumanoidRootPart.CFrame = CFrame.new(randomSpawn.Position)
	end
	
	ti = 10
	repeat
		ti = ti -1
		status.Value = ti.." seconds left!"
		wait(1)
	until ti == 0
	for i = 1, #plrs do
		plrs[i].Character.HumanoidRootPart.CFrame = workspace.SpawnLocation.CFrame + Vector3.new(0, 10, 0)
--VR PLAYER TP TO CERTAIN SPOT
	end
	
	workspace[current]:Destroy()
end

You can make it so VR players have there own maps and they get teleported to it

Or here

	for i = 1, #plrs do
		local randomSpawn = spawns[math.random(1, #spawns)]
		plrs[i].Character.HumanoidRootPart.CFrame = CFrame.new(randomSpawn.Position)
	end 

if the player is in VR they should have there own spawns in that island so other than spawns have VRSpawns with it

1 Like

tysm for the help! i really appreciate it

1 Like

If you want anything else feel free to dm me!

1 Like