Making VR Hands from Scratch

I will show you how to make vr hands from scratch!

by KingIntroAndMoreSub

Author Avatar

STEP 1 First, we need to check if the player is playing on VR. To do that is very simple, but first we need to make a localscript in StarterPlayer-StarterCharacterScripts

image|100x100 It should look like this!

STEP 2 Open up the local script and put in this

local VRService = game:GetService("VRService")

if VRService.VREnabled == true then
	
else
	print("NOT IN VR")
end

This will check if the player is in VR but if the player is not, it will print out "NOT IN VR"

STEP 3 Now we need to make the variables

local VRService = game:GetService("VRService")

if VRService.VREnabled == true then
    local player = game:GetService("Players").LocalPlayer -- Gets the player
	local character = player.Character -- Gets the player's character
	local camera = game.Workspace.CurrentCamera -- Gets the camera in the workspace
	local starterGui = game:GetService("StarterGui") -- Gets player's GUI

	player.CameraMode = Enum.CameraMode.LockFirstPerson
	camera.HeadScale = 1 -- Makes the camera's headscale to 1

	starterGui:SetCore("VRLaserPointerMode", 0) -- Removes the controller laser pointer
	starterGui:SetCore("VREnableControllerModels", false) -- Removes controller display
else
	print("NOT IN VR")
end

STEP 4 Now we need to create the player vr hands

local function createHand(handType)
	local hand = Instance.new("Part")
	hand.Parent = character
	hand.CFrame = character.HumanoidRootPart.CFrame
	hand.Size = Vector3.new(0.4, 0.4, 1)
	hand.Transparency = 0
	hand.Color = Color3.new(1, 0.72, 0.6)
	hand.Material = Enum.Material.SmoothPlastic
	hand.CanCollide = false
	hand.Anchored = true
	hand.Name = handType
	return hand
end

local leftHand = createHand("rightHand")
local rightHand = createHand("leftHand")

Put this in the VRService section

local VRService = game:GetService("VRService")

if VRService.VREnabled == true then
    local player = game:GetService("Players").LocalPlayer -- Gets the player
	local character = player.Character -- Gets the player's character
	local camera = game.Workspace.CurrentCamera -- Gets the camera in the workspace
	local starterGui = game:GetService("StarterGui") -- Gets player's GUI

	player.CameraMode = Enum.CameraMode.LockFirstPerson -- Locks player into FirstPersonMode
	camera.HeadScale = 1 -- Makes the camera's headscale to 1

	starterGui:SetCore("VRLaserPointerMode", 0) -- Removes the controller laser pointer
	starterGui:SetCore("VREnableControllerModels", false) -- Removes controller display

	local function createHand(handType)
		local hand = Instance.new("Part")
		hand.Parent = character
		hand.CFrame = character.HumanoidRootPart.CFrame
		hand.Size = Vector3.new(0.4, 0.4, 1)
		hand.Transparency = 0
		hand.Color = Color3.new(1, 0.72, 0.6)
		hand.Material = Enum.Material.SmoothPlastic
		hand.CanCollide = false
		hand.Anchored = true
		hand.Name = handType
		return hand
	end

	local leftHand = createHand("rightHand")
	local rightHand = createHand("leftHand")
else
	print("NOT IN VR")
end

Should look at this!

STEP 5 Now we need to make the hands follow the players VR controller!

local inputService = game:GetService("UserInputService")
inputService.UserCFrameChanged:Connect(function(part, move) 
	inputService.UserCFrameChanged:Connect(function(part, move)
		if part == Enum.UserCFrame.LeftHand then
			leftHand.CFrame = camera.CFrame * move
		elseif part == Enum.UserCFrame.RightHand then
			rightHand.CFrame = camera.CFrame * move
		end
	end)
end)		

This is making the left hand and right hand follow the vr controller the player is using.

local VRService = game:GetService("VRService")

if VRService.VREnabled == true then
	local player = game:GetService("Players").LocalPlayer -- Gets the player
	local character = player.Character -- Gets the player's character
	local camera = game.Workspace.CurrentCamera -- Gets the camera in the workspace
	local starterGui = game:GetService("StarterGui") -- Gets player's GUI

	player.CameraMode = Enum.CameraMode.LockFirstPerson
	camera.HeadScale = 1 -- Makes the camera's headscale to 1

	starterGui:SetCore("VRLaserPointerMode", 0) -- Removes the controller laser pointer
	starterGui:SetCore("VREnableControllerModels", false) -- Removes controller display
	
	local function createHand(handType)
		local hand = Instance.new("Part")
		hand.Parent = character
		hand.CFrame = character.HumanoidRootPart.CFrame
		hand.Size = Vector3.new(0.4, 0.4, 1)
		hand.Transparency = 0
		hand.Color = Color3.new(1, 0.72, 0.6)
		hand.Material = Enum.Material.SmoothPlastic
		hand.CanCollide = false
		hand.Anchored = true
		hand.Name = handType
		return hand
	end

	local leftHand = createHand("rightHand")
	local rightHand = createHand("leftHand")
	
	local inputService = game:GetService("UserInputService")
	inputService.UserCFrameChanged:Connect(function(part, move)
		inputService.UserCFrameChanged:Connect(function(part, move)
			if part == Enum.UserCFrame.LeftHand then
				leftHand.CFrame = camera.CFrame * move
			elseif part == Enum.UserCFrame.RightHand then
				rightHand.CFrame = camera.CFrame * move
			end
		end)
	end)	
else
	print("NOT IN VR")
end

It should look at this

STEP 6 Since the player is locked on to first person we need to make the player able to see the hands

local self,player = script.Parent,game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local humanoid = char:WaitForChild("Humanoid")

function antiTrans(part)
	if part and part:IsA("BasePart") and(part.Name=="leftHand" or part.Name=="rightHand") then
		part.LocalTransparencyModifier = part.Transparency
		part.Changed:connect(function(property)    
			part.LocalTransparencyModifier = part.Transparency
		end)
	end
end

for _,v in pairs(character:GetChildren()) do
	antiTrans(v)
end

This will make all the body parts invisible but the VR hands

local VRService = game:GetService("VRService")

if VRService.VREnabled == true then
	local player = game:GetService("Players").LocalPlayer -- Gets the player
	local character = player.Character -- Gets the player's character
	local camera = game.Workspace.CurrentCamera -- Gets the camera in the workspace
	local starterGui = game:GetService("StarterGui") -- Gets player's GUI

	player.CameraMode = Enum.CameraMode.LockFirstPerson
	camera.HeadScale = 1 -- Makes the camera's headscale to 1

	starterGui:SetCore("VRLaserPointerMode", 0) -- Removes the controller laser pointer
	starterGui:SetCore("VREnableControllerModels", false) -- Removes controller display
	
	local function createHand(handType)
		local hand = Instance.new("Part")
		hand.Parent = character
		hand.CFrame = character.HumanoidRootPart.CFrame
		hand.Size = Vector3.new(0.4, 0.4, 1)
		hand.Transparency = 0
		hand.Color = Color3.new(1, 0.72, 0.6)
		hand.Material = Enum.Material.SmoothPlastic
		hand.CanCollide = false
		hand.Anchored = true
		hand.Name = handType
		return hand
	end

	local leftHand = createHand("rightHand")
	local rightHand = createHand("leftHand")
	
	local inputService = game:GetService("UserInputService")
	inputService.UserCFrameChanged:Connect(function(part, move)
		inputService.UserCFrameChanged:Connect(function(part, move)
			if part == Enum.UserCFrame.LeftHand then
				leftHand.CFrame = camera.CFrame * move
			elseif part == Enum.UserCFrame.RightHand then
				rightHand.CFrame = camera.CFrame * move
			end
		end)
	end)	
	
	function antiTrans(part)
		if part and part:IsA("BasePart") and(part.Name=="leftHand" or part.Name=="rightHand") then
			part.LocalTransparencyModifier = part.Transparency
			part.Changed:connect(function(property)    
				part.LocalTransparencyModifier = part.Transparency
			end)
		end
	end

	for _,v in pairs(character:GetChildren()) do
		antiTrans(v)
	end
	
else
	print("NOT IN VR")
end

It should look like this!

STEP 7 We need to test it to see if it works!

image|100x100 It works! Only problem with this that other people will not see it and it will not match your skin tone on your roblox avatar but you can change the setting of the hand! Let me know if you have questions!

CREDITS

nathandecool1234 - Dev Forum

View in-game to comment, award, and more!