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

17 comments
Also no reason to include that spawn count thing with the wait() in there as it is currently doing nothing, you aren't even printing the value, it could decrease the time it takes to run by quite a bit if you just removed the wait().
Tried your method, but it does out that it spawns that part and doesnt fill up the empty spaces before the script completes and plus it makes the script's activity go up even more.
activity will always be high on nested loops, the only difference is that this will take significantly less time. As for not filling in spaces, I'll see if I can come up with a better solution.
Updated it, it should work, but if it doesn't then I know my brain is fried for the day.
This wouldnt work as each layer will generate twice
No, it shouldn't generate each layer twice, it jumps to the next value by 2 so that it adds 2 layers at a time.
Nope, tested it
I just had it print each set of 3 coordinates and none were the same.
Might have tested the code again and saw u changed the increment by 2.. woops. It works but the problem is it leaves spaces in between.
Yeah I see that now, going to tweak it again, give me a min
Also, as for the stress it puts on the server/client, in cases of lots of parts being generated like this, you'll need to either find a balance between speed and efficiency or just go on the extremes of one or the other.
Ok it has been updated and I am almost certain now that it shouldn't produce gaps, and if all that GeneratePart is doing is cloning and moving things around the workspace, then it won't cause enough lag to do anything harmful to the client/server connection.
Well ermmm, its still creating gaps but less now.
Played around with the increment and the x,y,z, and now it works with less lag and no gaps :D tks
Lol it took us so many tries to get it done :) I also updated mine again and I still don't know if it works exactly, but it doesn't produce gaps anymore.
Wow now the code looks too messy lol. i Just made the X increment by 2 and made the x value to x+1.
Oh ok, yeah that would do what this is doing, but only for one variable. Your solution would be decreasing the time it takes by just a bit without causing any lag by generating too many parts at the same time. So you finally found the balance between speed and efficiency :D