Yeah I was lifting for about 30-40 min and then usually go on the treadmill for about 30 min afterwards
Does that kill my gains of gaining muscle?
I'm just worried that all the exercising will make me too tired to study and my diet usually gets messed up due to the indulgence of sugary foods to give me energy :/
No, it doesn't kill your gains per se, but I think what does seem problematic about your approach is that you don't know what you want out of working out other than a vague idea of "getting fit." That's fine, most people starting out don't, and more power to you for getting your butt to the gym.
That being said, here is the generally accepted knowledge regarding gains (and some of my fellow weightroom bros might want to chime in here, as I am a small girl and my goal with lifting is NOT to gain lots of mass):
You maximize your gains through a regular routine, whether it's an upper-lower split, classic starting strength 3x5 compound lifts, stronglifts 5x5, or whatever. Use a program like this if you're serious about beginning lifting. They are popular because they work. Most of these programs advocate working out 4-5 days per week, with some variation.
I have yet to see a serious compound lift program that advocates ANY cardio. Some might say it's ok to tack it on after lifts, but for the most part, you want to give your body as much time to physically recover from your heavy lifting days as possible. You can maximize recovery by eating a ton and RESTING on your off days. You will see the most gains if you do this--have a protein shake after, eat enough, and rest in between lifts. On your lift days, ramp up to your working set, do 3-5 sets of 5 reps, and maybe throw in some dips or pull-ups. You don't need to mess around with plate-loaded machines unless you're training for something really specific.
However, perhaps I've misconstrued your motivations. Are you looking to improve your running too? Because even though it's not generally recommended for people trying to "tack on a lot of mass" (to quote Mac), it is possible to train for running while lifting. I took a break from my regular lifting program in June to train for a half marathon, and I lifted every other day. However, I changed my lifts from 3-5 sets of 5 reps (plus warmup) to 3 sets of 6-10 reps. I did more leg-specific and core work, and I didn't push myself as far with my squats. I was still really slow, but hey, I finished.
Either way, good for you for being so motivated about getting to the gym. That's really the most important part. It's a great way to relieve stress after spending way too much time studying.

I got serious about lifting right about when I got serious about being a hermit for the mcat, and I think it really helped me burn off a lot of anxious energy.