Script timeout: exhausted allowed execution time

Just yesterday my game worked fine. Today, whenever I test the game, it freezes for like 2 minutes and gives a load of “Script timeout: exhausted allowed execution time” errors.
After a bit of searching, it turns out every single wait(number) function in my game is freezing the game and giving that area.

How do I fix this?

What is your script?

Wait should help prevent the error, not cause it.

Can you show your code? We can’t help if you can’t show where the problem is.

1 Like

It’s every single piece of code in my game, it would take hours for me to copy & paste all the code here.

Nevermind the above. Instead, try restarting studio and see if that does anything.

It’s still happening after I restarted

Make sure that the task.wait()/wait() function is inside any while loop/repeat until loop blocks. It’s okay not using wait() on for loops unless they’re used too frequently.

Example:

-- This is what you should do to prevent script exhaustion
while true do
	for i, v in pairs(units) do
		
		if i % math.floor(#units/4) then
			task.wait()
		end
	end
	task.wait()
end

-- This is what you SHOULDN'T do to prevent script exhaustion
while true do
	for i, v in pairs(units) do
		task.wait()
	end
	-- no wait, so this script could get exhausted
end
2 Likes

its cuz the script is running too fast causing it to just stop. you should make number a higher number possibly or simplify the code itself

Make sure you have a wait, task.wait, etc in any loops. (While, for, repeat, etc)