Basically copied what this topic was doing but changed it into my own:
and works perfectly for what i want it to do