animate works as script but not function