Script timeout: exhausted allowed execution time

How does “Script timeout: exhausted allowed execution time” work?

I understand that from that error that there is a time execution limit for a thread to execute. However what doesn’t make sense is how task.wait() or wait() is able to prevent this since this just yields the thread and resumes it.

You may be wondering if I’ve left a while loop running without any yielding to it. But all I’m doing is simply calling a function that does 300 raycasts yet it errors.

I may be wrong, but I would think it hit something it couldn’t find or update, and it tried till it timed out.
I myself try to stay away from bare calls like task.wait(). I’ll always put something in, even if (0.33) figuring that will cover the FPS at least.

1 Like

I’ve tried limiting the raycast lengths to less than 200 studs. I tried yielding after every arbitrary amounts of iterations but the entire process slows down massively. The problem is that I am trying to do some recursive raycast with a set number of bounces but it seems to keep timing out. I was wondering if there was a way to prevent this without having to increase the process time.

If there is no other solution then I’ll have to make my own raycast function with my own custom shapes.

Maybe break it down to do smaller sub loops, till finished. Are you sure your recursive algorithm is working correctly? … Maybe try a smaller test to see.

1 Like

Smaller for loops works fine but the detail is less accurate. Yeah the algorithm works perfectly, it’s just the timeout value being in the way. This is basically the function causing the error

raycastFunc()
    local dir, pos
    local result
    for setAmountOfBounces do
        raycast(pos, dir * length, params)
        …
        — breaks if raycastResult is nil
        dir, pos = raycastResult…
        result …= …. — do stuff with result
    end
    return result
end```

Roblox only ever runs a single script at a time (excepting parallel lua features). When a script yields, like with a task.wait, it gives roblox a chance to let another script run for a bit—until that one yields.

The timeout refers to how long a script is allowed to monopolize Roblox’s script executor, i.e. how long it is allowed to run without yielding.

All that’s to say you need to add some waits somewhere to give roblox a chance to breathe and run other scripts, or you need to make your script finish more quickly. You might have some luck with parallel lua to run your raycasts in parallel.

1 Like

I am currently running it parallel right now. (3000 actors actually, dont ask, but it worked and it was beautiful watching the results pop up asynchronous with x15 the speed compared to serial.)

There are no other scripts running under parallel except for that function. If waiting is the only solution then that’s a shame cause that is really slow, and I mean really really slow.

If you could come up with a minimal reproducible example, it would go a long way towards being able to help you further. The limit for a scripts execution time is normally quite high compared to any computation you’d be doing.

Yeah. I think my only option is to batch yield. Cause my script is quite computationally demanding. My end goal is a software ray tracing system.