Using :clone() causes massive lag spikes

I am trying to equip player armor, but the current version is way to laggy.
Currently when equipping armor it lags the client by sending huge amounts of new data.

I honestly don’t know what to do anymore. could someone please help me?

Try preloading all the meshes in StarterPlayerScripts.

Mhm I think this won’t fix it, because currently what I am doing is when the player moves the armor piece in to one of the slots it will be cloned and placed inside the character and I think that is causing the lag, but I don’t know any other way to do it, I might need to not clone it and just place the instance inside the character, but this would mean changing the way the inventory system works.

Place this into a LocalScript in the StarterPlayerScripts and see if it works.

local folder --set the container
local list = {}
local f; f = function(folder)
	for i,v in next, folder:GetChildren() do
		if v:IsA("Folder") or v:IsA("Model") then
			f(v)
		else
			list[#list+1] = v
		end
	end
end
game:GetService("ContentProvider"):PreloadAsync(list)

Edited it a bit since apparently any instance can be thrown in.

Cloning instances usually doesn’t cause lag (the only exception would be trying to clone the entire workspace), and even if it did, your game would stall and stop responding (stutter, not lag). What you are seeing here is a mesh that still hasn’t been downloaded not being rendered, so it’s basically invisible.

You don’t have lag in any way, that’s just how Roblox avoids too much network usage.

This is kind of off topic, but :clone() is deprecated. Use :Clone() instead.

1 Like

I mean the Viewport Frame character display looks a bit slow because it has a wait(1) in the middle of it.

The script that I am fixing is the armor updater script it’s on the server-side.

When the player is equipping the armor the game stutters for everyone on in the game.

The pre-loading didn’t fix the network receiving or I don’t know if am using it wrong.

local folder --set the container
local list = {}
local f; f = function(folder)
	for i,v in next, folder:GetChildren() do
		if v:IsA("Folder") or v:IsA("Model") then
			f(v)
		else
			list[#list+1] = v
		end
	end
end

f(game.Workspace.Preload)

game:GetService("ContentProvider"):PreloadAsync(list)

Ps. I forgot to say that vest is mostly unions

Can you try replacing the CollisionFidelity on those to Box? The physics data is stored with the instance, and those can get pretty big.

Also I forgot to remove some properties from it whoops, but that shouldn’t add that much time to the loading time

You could try making the equipment client-sided with the server only sending an event when something is equipped.

It helped a little, but the received client is still jumping up to 200-500 KB/s

You won’t be able to fix this completely with handling everything on the server. It still needs to send the information every time you want to equip something. The only definitive solution is to handle the model on the client, while the logic still stays on the server.

To be honest, this shouldn’t be hard as there won’t be anything that can be exploited, just move the part that clones the model into a LocalScript which has a function connected to a RemoteEvent.

so basically I should add string values in to player to keep track of the current armors they have and then make a local script read them when player: connects, dies, changes clothes, etc…

I meant keeping logic the way it is. Take the code that you screenshot in the original post and move it into a LocalScript. Remove it from the server Script and replace it with a RemoteEvent fire. Make the LocalScript handle everything related to the model.

1 Like

ok I’ll see what I can do might need some ideas later…

Thank you!

1 Like