Need help with map generation script

  1. Hi everyone. I am making a map generation script for a new game. It currently works how it was written to, but I’m looking for a better way to go about this.

  2. The issue is that the system is very random, creating tons of spaces you can’t access whatsoever.

  3. So far, I’ve rewrote it twice, each time yielding the same results. My game is a bit too unique, and none of the other map generation scripts would work too well with the system I have.

local typenumber = 0
local roomnumber = 0
wait(1)
for i,v in pairs(workspace.Gens:GetChildren()) do
	wait(0.2)
	typenumber = math.random(1,10)
	if typenumber == 1 or typenumber == 2  then
		roomnumber = math.random(1,4)
		if roomnumber == 1 then
			local clone = game.ServerStorage.Corners.One:Clone()
			clone.Parent = v
			clone.Center.Place.Part1 = v
		elseif roomnumber == 2 then
			local clone = game.ServerStorage.Corners.Two:Clone()
			clone.Parent = v
			clone.Center.Place.Part1 = v
		elseif roomnumber == 3 then
			local clone = game.ServerStorage.Corners.Three:Clone()
			clone.Parent = v
			clone.Center.Place.Part1 = v
		elseif roomnumber == 4 then
				local clone = game.ServerStorage.Corners.One:Clone()
				clone.Parent = v
				clone.Center.Place.Part1 = v
		end
	elseif typenumber == 3 or typenumber == 4 or typenumber == 5 or typenumber ==  6 or typenumber == 7 then
		roomnumber = math.random(1,2)
		if roomnumber == 1 then
			local clone = game.ServerStorage.Halls.One:Clone()
			clone.Parent = v
			clone.Center.Place.Part1 = v
		elseif roomnumber == 2 then
			local clone = game.ServerStorage.Halls.Two:Clone()
			clone.Parent = v
			clone.Center.Place.Part1 = v
		end
	elseif typenumber == 8 then
		if roomnumber == 1 then
			local clone = game.ServerStorage.Spawns.One:Clone()
			clone.Parent = v
			clone.Center.Place.Part1 = v
		elseif roomnumber == 2 then
			local clone = game.ServerStorage.Spawns.Two:Clone()
			clone.Parent = v
			clone.Center.Place.Part1 = v
		elseif roomnumber == 3 then
			local clone = game.ServerStorage.Spawns.Three:Clone()
			clone.Parent = v
			clone.Center.Place.Part1 = v
		elseif roomnumber == 4 then
			local clone = game.ServerStorage.Spawns.One:Clone()
			clone.Parent = v
			clone.Center.Place.Part1 = v

		end
	end
end


image

If anyone has ideas for how to make this system better, or just something that I should add or change, please let me know.

1 Like

woah woah woah, “or” can’t be used like this

Sadly that’s wrong. It does work.

that if statement will always run because 4 - 7 exist

EDIT:

you did that same thing here

1 Like

Edited the code to fix it according to your suggestion.

1 Like

You can use a recursive backtracking algorithm to generate a maze that can be completed

2 Likes

I’ll look into this. Thank you.

1 Like