Well, I think I can tell you what your first problem is. The "=" in 'if ($time = $dupFrame * $count);' should actually be a "==" - the singe '=' is used for assigning values, while the double '==' is used for comparing them. Also, I'm not sure you're supposed to have a semi-colon at the end of the same line.
Without actually running the code, that's what stands out to me as being the most in trouble. Although there's certainly a number of things you could do to improve and tighten your code, to simply make it run that may be enough.
Book Wise
https://X4nd5r.deviantart.com