Why does this while loop give me an error?

You can create a custom delay node following this method that will accomplish what you want. Both videos should work the second is more versatile I believe.