read until end
So, I made this code:
But for some reason, after running 3 times, I get this error:
If you need clarification please ask.
Any help is appreciated.
Thanks!
read until end
So, I made this code:
But for some reason, after running 3 times, I get this error:
If you need clarification please ask.
Any help is appreciated.
Thanks!
This block here.
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!
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.
But you didn’t, I was suggesting a way to make your code better because I found a potential issue with it
What was the issue wasn’t the rest of the code it was the exhaustion time error. The table was there since the start.
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.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.