Script Timeout: exhausted allowed execution time PROBLEM

I’m trying to make a color block game that has multiple layers of blocks, but when I want to randomly want to color all of them, it just gets exhauseted and freezes (until it works [10 seconds]). I really want this to work but I have not found any solutions.I know this is a lot, but the amount of blocks is 720, and I want to color them all at once randomly every single round. Here is a screenshot of the script I have so far ( there are other variables defined earlier but most of them are self explanatory).

allowedColors is a table with all the colors I want there to be.

[EDIT: I TRIED USING TASK.WAIT() ALREADY]

you arent yielding the code, make sure you do with task.wait()

I should of said this in the post (sorry) but if I do that it takes like 10 seconds for each one to be colored randomly

You’re likely doing too many iterations at once. If there’s 720 blocks in your game and 16 players, your loop will run 11,520 times. This is combined by the fact that it runs 300 times as well (3,456,000 iterations).

1 Like

Also, why are you using a for loop with a for loop?

for i = 300, 0, -1 do -- why
    for a, Player in pairs(game.Players:GetPlayers()) do

you can remove the first for loop and it would work fine.

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