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.
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).
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.
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?
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:
The welds are cloned into the parts as well but the references in Part0/1 don’t copy over, or
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.