Automatic yielding of lengthy functions

I’ve implemented a pretty complex system for Bézier curves. I don’t need my system to run extremely fast since it’s used for procedural generation that occurs infrequently on the server. I wonder, however, how I might yield/wait a script dynamically in order to prevent max execution time runtime errors. The goal would be a system that never produces an error, regardless of the complexity and time a script takes, waiting at dynamic intervals determined by need.

If your code has iterations you can measure the time and call task.wait if it has taken longer than some threshold.