How do I clone to workspace with minimal lag?

I have a model in ReplicatedStorage that I intend to clone to workspace very often. However, each time I do, theres a visible stutter on the player’s frame rate.
The cloning is done in a server script, and If I do not parent the model to workspace no lag is observed. How should I go about removing this lag?
Thank you in advance!

1 Like

You likely can’t if the model is very large because parenting it to the workspace results in the entire model being rendered into the observable environment of the game. My only suggestion would be to try and decrease the amount of instances within the model and/or reduce the amount of times the model is cloned & moved to the workspace.

1 Like

You could separate the model into smaller parts and move them over one at a time, or cut out the middle man and iterate over the contents of the model directly - I do the latter when generating terrain, using a for loop and a counter like so:

local maxCycles = 32
local counter = 0

for i = 1, 1000 do
    -- do stuff here
    counter += 1
    if counter >= maxCycles then
        counter = 0

This is far faster than wait()ing between each instance, but also allows you to throttle the process back so as to not hang the server or clients.

1 Like

you can use for loops to get the children of your model and make a model in the workspace and then parent all of your original models children one by one with a delay, like this.

local myModel = game.ReplicatedStorage.MyModel -- change this to your model ofc
local model ="Model")

for i, v in pairs(myModel:GetChildren()) do
    local copy = v:Clone()
    copy.Parent = model
    task.wait() -- or task.wait(0.1) if it still lags.    

I hope this helps!


Due to the nature of my model (Humanoid NPCs) I opted for letting individual clients cloning them, with only a small part to represent them on the server. I hope this solution works for others too! Thanks for all the help.

1 Like