MPU 6050 callibration

So my project incorporates a MPU 6050, and I am having some troubles calibrating my variables. The variables drift, and after a few minutes, it really messes up the overall readings. I have figured out that the program I am using calculates the base calibrated variables (calculated every time in the setup function), and calculates the variables each loop, relative to the base variable. The problem is that the inaccuracy is enough to mess up the reading by quite a bit after a few minutes. Does anyone have any strategies to help figure this out? perhaps a compass module I can add, or some other kind of sensor that would help. Even a little bit of code that helps with this.
Thanks all!

What variables?

The accelerometer values should not drift, but the gyro values always do, and the drift rate depends on temperature. Correcting for the latter is a complex topic, which you can read about in many places. One such place is in this collection.

the final x, y, and z(yaw) variables all drift. The program takes 96% of the gyro x and y ,and adds it to 4% of the accelorometer x, and y. The z( yaw) is calculated on only the gyro, as the z on the accel is the gravity effect. What do you mean by the temperature?

"The program" is not doing a very good job of compensating for the gyro drift. Without a reference in the horizontal plane (like North), it cannot compensate for z rotational rate drift at all.

What do you mean by the temperature?

What the thermometer reads.

alright, so the yaw can be fixed with a gyroscope (I imagine...) but what about the other two? how do I succesfully calibrate them?

Say if I was to buy a MPU 9250? IT has a 3 axis magnometer. That will help with the yaw. But im still not sure about the x and y axes.

As I said, this is a complex project. It is clear that you have done little or no reading on how these various sensors and "sensor fusion" algorithms are used to determine orientation, so that would be a way to start.

Or your could download a well thought out AHRS program that works with your sensors. Here is one site that offers solid code and information: https://richardstechnotes.wordpress.com/category/rtimulib/

add filter in your code .it can be kalman or complementary filter.I guess this will help you