OMFG...

Replace all that wait(999) lines by the loop I posted above.

Also, note that those wait(999) are waiting a number of frames, not a given time, which means it can continue before the video is finished or continue too late.