For some reason, every time I call the :Destroy() function for the first time, it causes two major lag spikes. But after that, it doesn’t lag at all—only the first time.
I have also tryed this in the Roblox Player app and it dose not lag, its only in studio.
if you call :Destroy() on a model it will cause lag spikes as the game is destroying every model at the same time, but only in the first time… thats strange
Causes:
Having too much models in your game calling :Destroy()
A large model being called to Destroy
What you can do about it:
If wanting to destroy a large model, first make a CleanDestroy script to make the model firmly and rapidly destroys everything and not at the same time.
local function destroyModelSmoothly(model, delayTime)
if not model or not model:IsA("Model") then
warn("Invalid model")
return
end
local parts = model:GetDescendants()
local total = #parts
local batchSize = 50
delayTime = delayTime or 0.01
print("starting destruction of " .. total .. " objects...")
for i = 1, total, batchSize do
for j = i, math.min(i + batchSize - 1, total) do
local obj = parts[j]
if obj and obj.Parent then
obj:Destroy()
end
end
task.wait(delayTime)
end
print("Model destroyed smoothly!")
end
--put in your model to do it
local target = workspace:FindFirstChild("HugeModel") -- Replace with your model's name
destroyModelSmoothly(target)
if that doesnt work please explain what you are trying to destroy so i can help you better
If that’s the case for this specific place, then maybe add a script which creates a part once and destroys it afterwards at the start of the server/client so future destroys don’t spike the client/server ¯\(ツ)/¯
If it’s a case in other places as well, maybe you can file a bug report.