I am new to programming. I think I'm close to solving my issue, but it finally broke my brain and I need help. 
I am running a pygame script as a scheduled task in crontabs. I have one code that executes successfully and does what it should. I have another code that executes, but when it does the screen goes blank, usually displaying some lines that I usually see when the Linux boots up, and it just stays stuck there.
I have gone through both codes and absolutely everything is similar and correct. I have #!/usr/bin/env python at the start of each script.
(Elsewhere it was recommended that I give the exact version, because I use dictionaries in my script and apparently crontab could get confused with the dictionary stuff that pygame uses. I don't fully understand, I tried it but it didn't work on my raspberry pi so I don't think that's the solution.)
Each script runs fine in the terminal.
I have set the PATH variable to the one that the python script uses and also set the SHELL to /bin/bash. In the task I also have "export DISPLAY=:0" (e.g. 12 21 * * * export DISPLAY=:0 && ...). I have found this was the magic trick that got the other code to work. Which made me wonder if there is another environment variable that I need to set in the task? 
The difference between the first code and the second code: The second code uses pygame.mixer and plays sound files. In the script, the sound files are in dictionaries (e.g. sound = {"word" : "/absolute/path/to/file.wav", "word2" : ...etc} As I said this code runs fine in terminal.
So why does the one script work and not the other. Both use pygame. The other just uses sound, dictionaries instead of strings, and pygame.mixer as well. My reasoning is that there is an issue with crontab getting stuck on one of these things.
I fixed it. I was running it out of root. When I ran the crontab in the user it worked. It must be because the root couldn't get at the files.
Important tips is to add 'import os' and at some point in the script add 'print(os.environ)' to check all the environment variables when it runs in terminal.
Then copy the $PATH variables to the top of the crontab jobs.
Same with $SHELL.
The $DISPLAY variables need to be put in the line, so for example '* * * * * export DISPLAY=:0 && /usr/bin/python /home/user/file.py'
See how I put absolute paths for both the command and the path to file. I also set absolute paths to files in the script, even if the files are in the same folder as the script. I'm not sure if this is necessary I will check that next. I've seen a lot of people struggle with this issue and the advice usually comes down to these things.
Crontab executes python script but something is wrong