This is from a previous question I asked about 2 weeks ago on how to make a generation script have less activity on the server/client. It does reduce the amount of the activity by at least 25-30% (Reduced from 75-80% to 60-40% [Estimate values/numbers]). However, sometimes the script takes forever to generate. Time ranging from 8.5 mins - 12 mins. This is too long of a wait. So was wondering if there is any other way to substitute a nested for loop and keep the script's activity on the server/client below at least 30% if it is even possible. This is the only way I could think of to generate a Vector3 (x, y, z) cube. Note:
function GeneratePart calls a function to clone the part and calculates the position of it.
local SpawnCount = 0 for y = 1, 30 do for x = 1, 20, 2 do for z = 1, 20 do GeneratePart(x, y, z) GeneratePart(x + 1, y, z) SpawnCount = SpawnCount + 5 if SpawnCount >= 10 then wait() SpawnCount = 0 end end end end
The overhead of the nested for loop is going to be completely negligible compared to the time it takes to spawn parts and parent them into the workspace, so don't kill yourself trying to convert it to 1 loop. Those three loops with no functions inside will execute in microseconds, if that.
What's killing your performance is likely how you're spawning and parenting the parts inside GeneratePart. Nothing you show here accounts for this taking 10 minutes to run. There must be come real horrors happening in GeneratePart(), like using the 2-argument form of Instance.new or spawning huge, unanchored or overlapping parts, or something like that.
You might also be calling wait() more often than is needed. Try moving the wait() up to the x loop.
I have a triangle terrain demo place that spawns and orients 32,768 wedge parts, and the server only takes about 8 seconds to do this. So something is seriously amiss with spawning 6000 parts taking 8-12 minutes.