I’m trying to make a nice volcano that spews lava bricks everywhere. It pretty much does what I want it to do. The problem is, instantiating those blocks is visibly laggy, so they freeze for a second when created, and then fling. Is there a better way?
for i = 1, game.Workspace.Assets.Intensity.Value + 1 do
local volcanoBlock = game.ServerStorage.Lava:Clone()
volcanoBlock.Size = Vector3.new(math.random(8, 20), math.random(8, 20), math.random(8, 20))
volcanoBlock.Velocity = Vector3.new(math.random(-150, 150), math.random(75, 175), math.random(-150, 150))
volcanoBlock.RotVelocity = Vector3.new(math.random(-10, 10), math.random(-10, 10), math.random(-10, 10))
volcanoBlock.Parent = game.Workspace
volcanoBlock:SetNetworkOwner(nil)
game.Debris:AddItem(volcanoBlock, 10)
end
Should I use Instance.new(“Part”), and then give it properties instead of cloning a preexisting part?
To your question about whether you should be using instance.new to cut down on lag and whether it truly affects performance, my answer is yes but no, i believe cloning is actually faster but that doesn’t mean that it creates less lag , A more likely culprit of the supposed lag could possibly be physics and or collisions, if your game allows maybe disabling something like cancollide is an option?. However my main question is does this actually affect performance other than visually?( i.e something like fps) , if not then this “lag” could just be a “visual lag” (as you said), caused by physics (velocity and rotvelocity) taking a second to “start up” upon the object being created ( if that makes sense, also don’t quote me on that ) or even something directly or indirectly related to how you handle your instances in general.
Here is a post you might want to scan over, if you have any concerns about if you should use Clone or Instance.New, and @colbert2677 makes a good point there :
Another reason (i think unlikely) could be due to a possible hangup, in that case simply waiting before creating a new part should take care of that.
Also if you can, providing a video of what’s happening might be helpful!
The reason that this “lags” is that it’s trying to generate all of the new blocks required at the exact same time which takes up all the game processing power within that time. I would recommend just adding a simple wait. I also recommend rendering this client side if you arent already.