Is there a way to clone a gigantic model without welds breaking or the server lagging?

I have been having issues with server crashes whenever there are models with over 3000 blocks in it being cloned.

I have tried cloning every single block and moving it into a model, but that caused the welds to break.

Is there a way to clone a model with lots of parts in it without the server lagging and without the welds breaking?

1 Like

3000 is a lot of parts, you can clone every single block which might spread out the impact more given you don’t do it all at once but moving the parts or only partially cloning what was needed for the weld will break it, you can always recreate it. If you need to clone the entire model you’re not getting around having to clone it, but you can make the player experience better by perhaps cloning a set amount of models you need at the start (resource pooling) or try converting your many parts into fewer meshes instead, this will also increase performance.

2 Likes

If you have a lot of parts put together in a divisible shape (like a doorway in a wall) try making them into a union.

I’ve seen some articles which state that unions and meshes are much less expensive for the game engine to render (especially for unions, because CSG does most of the processing at the time of creation).

3 Likes

Thats not possible for my game sadly.

2 Likes

Can you describe this model more?

Is it dense or sparsely positioned parts in your model?
You could try to make your parts invisible whilst cloning, it would improve the performance one way or another. To try to stop spikes happening you could also have cooldowns:

count = 0
for i,v in pairs(modelchildren)do
   if count == 100 then game:GetService("RunService").RenderStepped:Wait() count = 0
   count = count + 1

If you’re doing this on the server then use Heartbeat instead.

3 Likes


all of those blocks are pre-welded

1 Like

No.

You are unwilling to split your plane into pieces and there is only one method that is capable of cloning. You have quite literally no other options.

2 Likes

Perhaps you could describe more about your situation?

What is the purpose of cloning this gigantic model? Meaning, besides getting a copy of all the parts, what how are you trying to use the cloned or copied parts? Knowing this might help someone to offer an alternative approach for your use case.

Why does this model need 3000 parts? From the white aircraft image, depending on your use case, it seems to someone who does not know about your game as though it may be possible to create a similar model with perhaps 10% of the parts. Maybe some parts could be resized to be longer in one dimension instead of using many parts over that same distance?

If welds are used, why do you say unions are not possible in your game?

2 Likes

Split it into pieces,but usally it dosent lag if you group,that works for me

You just need to load everything in one-at-time. A simple for loop usually does the trick for me:

for i, v in pairs(plane:GetChildren()) do
   v:Clone().Parent = game.Workspace
end

Also DO NOT follow @uJordy’s advice. That will only make your performance worse.

Pretty sure he’s already tried this.

If the welds are breaking, you can just clone the welds first, clone the original weld’s Part0’s and Part1’s, set the weld clone’s properties to the part clones, and keep track of what has already been cloned so that (a) welds with the same Part0’s and Part1’s don’t conflict with each other, and (b) cloning parts later won’t be a hassle. There are two unforeseen cases that I cannot predict. Either:

  1. The welds are cloned into the parts as well but the references in Part0/1 don’t copy over, or
  2. The welds are destroyed altogether

There are also two types of welds in the game currently, that being a Weld and a WeldConstraint. I will be solving for WeldConstraint here:

function cloneModelWIthWelds(model)
	local newModel = Instance.new("Model") -- create model to return
	local AlreadyCloned = { -- self-explanatory
	 -- [original] = clone
	}
	for _, child in pairs(model:GetDescendants()) do
		-- if child is a weld and Part0 and Part1 exists,
		if child:IsA("WeldConstraint") and child.Part0 and child.Part1 then
			local newWeld = child:Clone()
			local p0, p1 = AlreadyCloned[child.Part0], AlreadyCloned[child.Part1]
			-- if part has not already been cloned, clone and index it
			if not p0 then
				p0 = child.Part0:Clone()
				AlreadyCloned[child.Part0] = p0
			end
			if not p1 then
				p1 = child.Part1:Clone()
				AlreadyCloned[child.Part1] = p1
			end
			AlreadyCloned[child] = newWeld
			newWeld.Part0, newWeld.Part1 = p0, p1
			newWeld.Parent = p0
			p0.Parent, p1.Parent = newModel, newModel
		end
	end
	
	for _, child in pairs(model:GetChildren()) do
		if not AlreadyCloned[child] then
			child:Clone().Parent = newModel -- thanks Intended_Pun
		end
	end
	return newModel
end

Disclaimer: I accidentally pressed Ctrl+Enter, but I don’t want to delete the post.

It is quite possible that the welds for two parts is stored as a child of one of the parts.

Because of the way you want to go about cloning the model, one part will end up cloned first.

This will break the weld between the first part and the second part, so your unpredictable case number 2 is very likely to occur.

In the game people are able to create their own creation which means the block count could be from 0 to 10000 blocks.

And unioning is not possible because the parts have to be saved in their pre-made form.

Anchor everything and re-weld it after it’s in workspace then.

To add on, you can use qPerfectionWeld made by Quenty which makes welding a breeze to do.

1 Like

I don’t know if this is solved already, but make a script where you clone the blocks and weld them all together?