Lag spike when claiming tycoon

This lag spike occurs when a player claims a tycoon.
Once claimed, the saved tycoon model is just cloned into workspace. Since server scripts cannot run in serverstorage, the whole tycoon is loaded and whatever the player never bought, it removes it. This causes a huge lag spike because the tycoon is big.

My question is, how would I solve this lag spike?

GIF:
https://gyazo.com/e2f887f7e981dbe4c8eddda9143f4b9d

Create a new empty model in workspace, then iterate through the model’s children and clone them individually with a small time interval in-between. Place each cloned child into the new model you’ve made. This will reduce lag but make the cloning take a bit longer.

1 Like
for i,v in next, Tycoon:GetDescendants() do 
	--// check if the player doesnt own the upgrade
	v:Destroy()
	task.wait(0.02)
	
end

this will not instantly destroy all the parts that the player doesnt own yet

This helps a bit, but the whole tycoon will still load once the player claims it.

I see how you’re going with this, but I can’t quite understand how to implement it into my system.

This is what I originally had:

if button:FindFirstChild("Object") and purchases:FindFirstChild(button.Object.Value) then
	object = purchases[button.Object.Value]
	objects[object.Name] = object:Clone()
	object:Destroy()
end