a common problem ive encountered with system.runTimeout() is that it breaks when leaving the world, cancelling any scheduled code. so i made an alternative Scheduler class to solve the problem.
https://gist.github.com/Dismalitie/95c06e5b79e8ccbd067363b7e846cd8f
Scheduler.scheduleFunc(delay, func) isnt perfect, and has some limitations:
funcmust be a lambda function (() => {})- code run through
Scheduler.scheduleFunc()is in its own scope, so you'll have to re-import stuff - lambda function code cant exceed the character limit of world dynamic properties
so to solve some of those problems, you can use Scheuduler.scheduleScriptEvent(). just make sure the event is defined at runtime.
important notes:
Scheduler._initialize()must be run before scheduling anything- if using
Scheduler.scheduleFunc(), you must have thescript_evalcapability enabled in your bp's manifest