Exhausted allowed execution time help

read until end

So, I made this code:

image

But for some reason, after running 3 times, I get this error:
image

If you need clarification please ask.

Any help is appreciated.

Thanks!

3 Likes

This block here.
image

This is considered a loop. And as you know in loops, if there’s no yielding function, it’ll go for as long as it wants, hence the script timeout. To fix this, just simply add a yield like task.wait() between repeat and until.

repeat
	task.wait(0.1)
until chosenIndex ~= OldIndex do
	chosenIndex = math.random(1, #tips)
	print(chosenIndex)
end

Hopefully this helps. If so, mark this as a solution (though it’s not required, but help others) and have fun with your project!

4 Likes

The problem with this approach is that the script unnecessarily wastes time waiting for the random function to generate an index that isnt the old one. A better solution would perhaps be to store a table of available tips, and randomly generate a number from 1 to the size of the table, and just index it.

1 Like

That is exactly what I did:

1 Like

But you didn’t, I was suggesting a way to make your code better because I found a potential issue with it

1 Like

What was the issue wasn’t the rest of the code it was the exhaustion time error. The table was there since the start.

1 Like

Well you fixed the exhaustion time error but I saw another issue with the code, sorry I should’ve explained it a little bit better.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.