In my game, a player can have a very large plot. This plot needs to be cloned at certain times, which, since its so big it draws back Game Script Timeout and essentially breaks the game. How can I add waits to this to avoid it?
You would have to make your own function that clones the descendants of the model in increments. Try this:
local contents = workspace.Plots:FindFirstChild('cool plot name')
local descendantNumber = 0
local oldHalt
local function iterate(model, parent)
for i,v in pairs(model:GetChildren()) do
if descendantNumber % 50 == 0 and descendantNumber ~= oldHalt then
wait()
oldHalt = descendantNumber
end
if v:IsA('Folder') or v:IsA('Model') then
local container = Instance.new(v.ClassName)
container.Parent = parent
container.Name = v.Name
iterate(v, container)
else
descendantNumber += 1
v:Clone().Parent = parent
end
end
end
iterate(contents)