This script i have spawns parts in a Vector3 dimension. But when i ran the script and check the Dev console, the script easily went up to activity of the script went up to at least 80% or more. Was wondering if there is any other way around this to help the server improve better. Suggestions or answers will help.
local SpawnCount = 0 for y = 1, 30 do for x = 1, 20 do for z = 1, 20 do GeneratePart(x, y, z) SpawnCount = SpawnCount + 1 if SpawnCount >= 10 then wait() SpawnCount = 0 end end end end
What you did was the easiest way of going through this problem, it is honestly completely fine, the only reason it is taking so long is because it is looping 12 thousand times. You can cut that down by a fraction by doing some simple math.
for y = 1, 15,2 do for x = 1, 10,2 do for z = 1, 10,2 do GeneratePart(x,y,z) GeneratePart(x,y+1,z) GeneratePart(x+1,y,z) GeneratePart(x,y,z+1) GeneratePart(x+1,y,z+1) GeneratePart(x,y+1,z+1) GeneratePart(x+1,y+1,z) GeneratePart(x+1,y+1,z+1) end end end
That just cut your time in half by spawning multiple things in at a time, you can cut it down further by doing more like that if you wish.
You should never use wait() without a parameter, and do you really need to execute a loop 30 times to make another loop that loops 20 times that makes another loop to loop ANOTHER loop that loops for 20 times to generate a part?