Reduce lag with high instance count

I am created a game made of blocks, and the world is made up of many of these blocks. Currently the “world” is a flat ~baseplate sized world consisting of many blocks that make it up. Due to the number of blocks / parts, this lags quite a bit sometimes.

For instance, I have to load the world in slowly / with waits. This is visible when you first join the game, you will see the world being created slowly. If I tried to do this all at once it crashes the game / it crashed studio. I could make the game start out with the world already created, but as I was duplicating the blocks in studio it was really slowing down.

What could I implement, likely script-wise, to lower the lag? I don’t believe I can do much building-wise.

Here is my game:
https://www.roblox.com/games/3588127591/Voxel-game

2 Likes

This why a game like Minecraft made a chunk loading system, it wouldn’t load littearly all the blocks in the game it loads the blocks that are close to you, so yeah I think making a chunks sytem is a possibility, all though than you have to use something that makes you able to control what loads and what not, and I don’t think that is a thing in the roblox api from what I know.

1 Like

It is completely possible! But yes @starmaq is right, using a chunk loading system to control what is currently replicated to the client and what isn’t will reduce the lag by a ton! Check out Chunk Loading System?

2 Likes

I’m not sure if the issue is that low-end clients can’t play smoothly. I think the issue is with the generation of the map when it first starts. I played a bit, and only noticed server-side lag while it was generating the map. This could just be my computer, but I’m not sure.

There is lag while generating the map, however especially on lower end computers, there may be a noticeable drop in FPS when looking at areas with a high amount of blocks, such as the ground. That is what I’m experiencing.

For starters, it’s more efficient to parent things in large batches after all their properties have been set than doing it 1 by 1, if this generation is being done on the server, since it saves network effort.

Also, you may want to look into merging multiple adjacent blocks of the same type into one single cube or polygon instance and only create separate instances when it’s needed to be split. You may also want to set invisible or reparent any cubes locally that can’t be seen, such as any covered on all 4 sides by other cubes. If I remember correctly, setting an instance’s transparency to 1 completely removes it from the render queue, but reparenting somewhere outside of workspace might also save up on not having to calculate its physics when touching.

12 Likes

Ah, okay. I think that chunk loading system will be great then. Good luck!