Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Vr head tracking stops working when dying?

I'm trying to use the Roblox default code for VREnabled and UserInputService and it works just how I want it to until you die. Once you reset, your character will no longer move its head to where you're looking. Here is the normal code:

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

I tried fixing this by checking when the player died but had no luck. example:

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
	character.Humanoid.Died:Connect(function()
	-- 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)
end

I'm trying to make a game similar to this. But I'm having trouble understanding how to use all this since there aren't many tutorials other than the Roblox developer page. I'd appreciate any links you can send me or ways to fix this.

1 comment

0

I don't really know how to make a vr game on roblox, but I think it has to do with that you have to wait for the character to respawn.

1 answer

✓ Accepted answer

Try putting your localscript in StarterCharacterScripts. This means when u respawn, the script will be put in the char. so each time the player dies he gets a new copy of this script and the character variable will this way always hold the reference to the correct char

This discussion is preserved as it was. New answers, comments, and votes are closed.