You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Stop it from crashing my studio.
What is the issue? It’s crashing roblox studio!
What solutions have you tried so far? How to stop coroutines.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
It crashes when it finishes or when I press Stop.
It’s crashing, I don’t know why but I think it’s todo with task.spawn() but when I remove it it still crashes.
Here is my code:
local plotTypes = {};
local occupiedPlots = {};
local maxPlots = 900;
local maxSize = 900;
local plotSize = 30;
for _,plotType in ipairs(script.PlotTypes:GetChildren()) do
table.insert(plotTypes, plotType); -- // Place each plotType into the plotTypes Table
end;
for loop=1,maxPlots do
local chosen = plotTypes[(math.random(1,#plotTypes))]; -- // Choose a random plotType from the plotTypes Table
local chosenPosition:Vector3;
repeat
task.spawn(function()
local corner1 = Vector3.new(435, 0.5, 435);
local corner2 = Vector3.new(-435, 0.5, -435);
local minX = math.min(corner1.X, corner2.X);
local maxX = math.max(corner1.X, corner2.X);
local minZ = math.min(corner1.Z, corner2.Z);
local maxZ = math.max(corner1.Z, corner2.Z);
local x = math.random(minX / plotSize, maxX / plotSize) * plotSize;
local z = math.random(minZ / plotSize, maxZ / plotSize) * plotSize;
chosenPosition = Vector3.new(x, 0, z);
end);
until occupiedPlots[tostring(chosenPosition)] ~= true;
occupiedPlots[tostring(chosenPosition)] = true;
local cloned = chosen:Clone();
cloned.Parent = workspace;
cloned.Position = chosenPosition;
task.wait();
end;
Just to let you know, it generates a map from different parts I have made an then randomly places them on the baseplate. (I am going to change the parts to Unions and Models.
Adding the task.wait() slows it down a lot. However it no longer crashes. Thanks for your response. Do you think I would be able to make it go quicker?
That type of loop is going to be a bit slow … pretty sure task.wait() is about as fast of a pause as you can get … Unless you put that on a 1 in 5 type of pause … every 5th time pause, kind of thing. Or what ever works the best.
The fact you said it works without crashing with the pause proves this was the real problem.
As you isolated it down to show the error. You simply overloaded it …