This work presents TransMolVAE, a Transformer-based variational autoencoder for molecular generation using SMILES. RNN-based models such as SmilesVAE often face posterior collapse. This happens when the latent space is not well used. To solve this, TransMolVAE applies self-attention. This allows the model to capture long-range patterns in SMILES strings. It improves reconstruction accuracy, keeps KL divergence stable, and makes better use of the latent space. The experiments showed strong results. Token accuracy increased steadily, reaching 0.72 by the fifth epoch. In contrast, SmilesVAE stayed low at 0.25. Validity, uniqueness, and novelty of molecules generated by TransMolVAE also reached above 70%. For SmilesVAE, these values were only between 50% and 55%. These findings show that TransMolVAE can generate more valid, novel, and diverse molecules compared to the baseline. The number of active units also stayed high, proving that the latent space was fully used. There was a trade-off in computation. TransMolVAE needed longer CPU time per epoch compared to SmilesVAE. This is because Transformer models are more complex and require higher computation. Even so, the improved quality of molecule generation makes TransMolVAE more suitable for drug discovery, where novelty and diversity are more important than speed.