You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? I want to make a generated “wall” that reaches a specific limit.
What is the issue? The output prints "Script timeout: exhausted allowed execution time"
What solutions have you tried so far? I’ve looked for solutions all around the devforums, but I cannot find something similar to my problem.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
local fullY = 48
local X = (-MAP_RANGE + 3)
function CapacitateFull()
local FullBlock = table.unpack(BiomeModule.GroundMaterials.FILL):Clone()
FullBlock.Parent = workspace.World._TempFolder
FullBlock.Position = Vector3.new(X,fullY,0)
local function runCheck()
if X <= (MAP_RANGE - 3) then
if FullBlock.Position.Y <= 0 then
FullBlock:Destroy()
fullY = 48
X = X + 3
wait()
CapacitateFull()
else
fullY = fullY - 3
CapacitateFull()
end
else
FullBlock:Destroy()
end
end
runCheck()
end
So what’s happening here is every time a block is placed in a specific position, it detects if it’s in the correct Y pos. If it is, it changes the Y and X values and runs the function again. If it’s hit the Y limit, then it gets destroyed and it moves on to another row. like a column. Is there a better way I can execute this?
If your recursion stopped, the script wouldn’t reach a timeout. Try to print when the recursion is supposed to stop. Make sure it is printed. If not, your recursion is probably still running.
local fullY = 48
local X = (-MAP_RANGE + 3)
function CapacitateFull()
local FullBlock = table.unpack(BiomeModule.GroundMaterials.FILL):Clone()
FullBlock.Parent = workspace.World._TempFolder
FullBlock.Position = Vector3.new(X,fullY,0)
local function runCheck()
if X <= (MAP_RANGE - 3) then
if FullBlock.Position.Y <= 0 then
FullBlock:Destroy()
fullY = 48
X = X + 3
wait()
CapacitateFull()
else
fullY = fullY - 3
CapacitateFull()
end
else
FullBlock:Destroy()
print("ENDS HERE")
end
end
runCheck()
end
Edit: also, when it says script timeout, I don’t think it necessarily means that it runs forever, right?
That is in your error: Script timeout: exhausted allowed execution time.
I am pretty sure it does mean that. I sometimes get that error in while loops.
When I add a condition to stop, and it is reached, I don’t get the error. Or a wait, so it doesn’t run too quickly.
Test your question, you added a print to see if it stops.
Because the runCheck’s first block statement is always true; this is causing it to continue on & on forever.
Depending on your scenerio you could try another approach.
Map_Range doesn’t change, and it doesn’t need to be. Let me make it simple:
Each column has 16 blocks with a size of 3,3,3. it makes up 48.
Everytime it passes the maximum blocks inside a column, it destroys that block, goes to another row,
and increases X. (by 3)
Edit 2: Map_range is like the amount of columns ther are. Currently, it’s 2670.
Maybe that’s the problem, that the script just repeats the recursion too many times, that it exceeded the allowed execution time, and reached a timeout.
Because you expect the recursion to run a lot of times.
I think it is best here to move to another approach, maybe with loops, and with a wait in the loop.
Or you can try increasing the wait in your recursion, however, I am not 100% that’ll work.
You are going to loop your checks, but instead of functions calling each other and killing the memory (recursion is very wasteful, it uses lots of memory), you are just going to loop the check and break it when finished.
local fullY = 48
local X = (-MAP_RANGE + 3)
local finished = false --When it's true, loop will break.
local function check(FullBlock)
if X <= (MAP_RANGE - 3) then
if FullBlock.Position.Y <= 0 then
FullBlock:Destroy()
fullY = 48
X = X + 3
else
fullY = fullY - 3
end
else
FullBlock:Destroy()
finished = true --Break the loop.
end
end
while true do --Loop your check
local FullBlock = table.unpack(BiomeModule.GroundMaterials.FILL):Clone()
FullBlock.Parent = workspace.World._TempFolder
FullBlock.Position = Vector3.new(X,fullY,0)
check(FullBlock) --Your Check function
if finished then break end --When it's finished, break it.
wait() --Wait
end
print("Loop ended")