if UserInputService.VREnabled and VRUseHeadsetControls.Value==true then VRService.UserCFrameChanged:connect(function(W,T)local X,Q=T:toEulerAnglesXYZ()local t=1.2 if W==Enum.UserCFrame.Head then if-X*t>-1 and-X*t<1 then Direction=-X*t elseif-X*t>0 then Direction=1 elseif-X*t<0 then Direction=-1 end if-Q>-1 and-Q<1 then Steer=-Q elseif-Q>0 then Steer=1 elseif-Q<0 then Steer=-1 end end end)end UserInputService.InputBegan:connect(function(W,T)if WeldObject.Value~=nil then if W.KeyCode==Enum.KeyCode.Space or W.KeyCode==Enum.KeyCode.Backspace or W.KeyCode==Enum.KeyCode.ButtonA then Hopoff()end if W.KeyCode==Enum.KeyCode.W or W.KeyCode==Enum.KeyCode.Up or W.KeyCode==Enum.KeyCode.ButtonR2 then if Direction~=1 then Direction=1 end end if W.KeyCode==Enum.KeyCode.S or W.KeyCode==Enum.KeyCode.Down or W.KeyCode==Enum.KeyCode.ButtonL2 then if Direction~=-1 then Direction=-1 end end if W.KeyCode==Enum.KeyCode.D or W.KeyCode==Enum.KeyCode.Right then if Steer~=1 then Steer=1 end end if W.KeyCode==Enum.KeyCode.A or W.KeyCode==Enum.KeyCode.Left then if Steer~=-1 then Steer=-1 end end end end)

if UserInputService.VREnabled and VRUseHeadsetControls.Value == true then
	VRService.UserCFrameChanged:connect(function(CFrametype,VRSpot)
		local x,y = VRSpot:toEulerAnglesXYZ()
		local Sensitivity = 1.2
		
		if CFrametype == Enum.UserCFrame.Head then
			-- Direction
			if -x*Sensitivity > -1 and -x*Sensitivity < 1 then -- Makes sure the headset isn't tilted too much
				Direction = -x*Sensitivity
			elseif -x*Sensitivity > 0 then -- Otherwise we'll go to the max speed
				Direction = 1
			elseif -x*Sensitivity < 0 then -- Otherwise we'll go to the max speed
				Direction = -1
			end
				
			-- Steering
			if -y > -1 and -y < 1 then -- Makes sure the headset isn't tilted too much
				Steer = -y
			elseif -y > 0 then -- Otherwise we'll go to the max speed
				Steer = 1
			elseif -y < 0 then -- Otherwise we'll go to the max speed
				Steer = -1
			end
		end
	end)
end

UserInputService.InputBegan:connect(function(Key,ProcessedEvent)
	if WeldObject.Value ~= nil then
		
		-- Hop off segway if press Spacebar, Backspace or controller A button
		if Key.KeyCode == Enum.KeyCode.Space or Key.KeyCode == Enum.KeyCode.Backspace or Key.KeyCode == Enum.KeyCode.ButtonA then	
			Hopoff()
		end
		
		--Forward
		if Key.KeyCode == Enum.KeyCode.W or Key.KeyCode == Enum.KeyCode.Up or Key.KeyCode == Enum.KeyCode.ButtonR2 then
			if Direction ~= 1 then
			Direction = 1
			end
		end
		
		--Backward
		if Key.KeyCode == Enum.KeyCode.S or Key.KeyCode == Enum.KeyCode.Down or Key.KeyCode == Enum.KeyCode.ButtonL2 then
			if Direction ~= -1 then
			Direction = -1
			end
		end
		
		--Left
		if Key.KeyCode == Enum.KeyCode.D or Key.KeyCode == Enum.KeyCode.Right then
			if Steer ~= 1 then
			Steer = 1
			end
		end
		
		--Right
		if Key.KeyCode == Enum.KeyCode.A or Key.KeyCode == Enum.KeyCode.Left then
			if Steer ~= -1 then
			Steer = -1
			end
		end
	end
end)
