Script Crashing Studio - Map Generator

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Stop it from crashing my studio.

  2. What is the issue? It’s crashing roblox studio!

  3. 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

for loop=1,maxPlots do
	local chosen = plotTypes[(math.random(1,#plotTypes))]; -- // Choose a random plotType from the plotTypes Table

	local chosenPosition:Vector3;

			local corner1 =, 0.5, 435);
			local corner2 =, 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 =, 0, z);
	until occupiedPlots[tostring(chosenPosition)] ~= true;

	occupiedPlots[tostring(chosenPosition)] = true;

	local cloned = chosen:Clone();
	cloned.Parent = workspace;
	cloned.Position = chosenPosition;

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.

If this part is not true this loop will run at warp speed till you lock up or crash.
This needs a slight pause …

1 Like

Alright, i’ll try adding a task.wait. Thanks for you response

Also , there must be a point where that is not coming out as you wish and sticking to false. OR it is just too much to do without a pause …

1 Like

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.

1 Like

Yeah, i’m not sure how to make it go quicker. That’s why I originally used task.spawn()

Oh alright, thanks for the help. I appreciate your response. :slight_smile:

local n = 0
--the loop
n +=1
if n > 7 then task.wait()
n = 0
--end loop
1 Like

Yes I will put it on a 1 in 5 pause. Thanks so much!

this may help too …

local corner1,corner2,minX,maxX,minZ,maxZ,x,y = 
-- the loop

corner1 =, 0.5, 435);
corner2 =, 0.5, -435);
minX = math.min(corner1.X, corner2.X);
maxX = math.max(corner1.X, corner2.X);
minZ = math.min(corner1.Z, corner2.Z);
maxZ = math.max(corner1.Z, corner2.Z);
x = math.random(minX / plotSize, maxX / plotSize) * plotSize;
z = math.ra

-- end loop

looking to cut down the work load as we go.

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 …

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.