How would I make a randomly generated maze with pre-made models?

Hello, I am currently trying to make a system to randomly make a maze.
I have been trying for the last hour and I have no clue how it could be done.
Here is my current pre-made parts for the maze.

Here is a place file too make it easier for you all too help:
Maze_Parts.rbxl (21.6 KB)

Feel free too add more pieces too this maze.
All the pieces are in the file in ReplicatedStorage.

Any help will be great, have a great day and stay safe.


so are you trying to make a thing like ToH where like it randomly generates a map every 7 minutes?

1 Like

Accentually yes, but I just want it too make a really hard maze that is possible.
Maybe even have the difficulty able to be made easier/harder in the script with a “local Difficulty = 1” the higher it is the harder it is.
That “local Difficulty = 1” doesn’t have too be done since I should be able todo that.

You should make 2 more sections, one with 3 open sides and one with 4 open sides.

I will update the file too add those


local dif = 0

while true do
   dif = dif +1
   if dif == 1 then
      local Map1 = game.ServerStorage.Map1:Clone()
      Map1.Parent = workspace
   elseif dif == 2 then
      local Map2 = game.ServerStorage.Map2:Clone()
      Map2.Parent = workspace
-- so on

Well, this would work for a TOH type game but making the parts connect would be quite hard

what do you mean? Just group all of the parts together and name it Map1 for example and put it in server storage

He wants a randomly generated maze, not a statically pre made map if I am right.

1 Like

Yes, that is correct.
I would like a randomly generated maze with models connecting to make it possible

I have updated the file now.
The 2 new maze parts are added


local dif = 0
local Pos = 0.5 -- sample
local a = 0

while a <= 50 do
  local Part ="Part", workspace)
  Part.Position =,Pos,0,0) 
  Part.Size =,0,0,0)
  Part.Anchored = true
  a = a +1

That seems to just create parts.
And I would like to use the models I have made for the maze so I can easily add parts the exact same but traps.

Don’t you want a random maze???

Yeah, that only creates a part tho not changing anything.
Creates a part sets the pos then size then repeats with nothing changing.

@Kamlkaze_Kid did you like not read the post?? While yeah that can be helpful, it’s not helpful in this case
I’d recommend reading up on maze generation algorithms, a few I’ve found to be helpful are on wikipedia
I wouldn’t recommend using pre made parts, simply because it is harder to create a maze with pre made parts than it is to create a maze with dynamic parts.
If you must use premade parts, use the primarypart and :SetPrimaryPartCFrame and a loop, pseudo code below:

for x = -10,10 1 do -- loop 20 times
    for y = -10,10,1 do
        local RandomModel = randomModel
        RandomModel:SetPrimaryPartCFrame( * gridSize, 0, y * gridSize))
        RandomModel.Parent = workspace

This maze doesn’t always turn out solvable, nor does it have walls (You can add these with other parts though), all it does it choose random parts and creates a grid with them.


If I am right, you want to have features like a randomly generated maze with the parts you have given in the Post right?

My approach to this would be making a good maze generation algorithm, because if you just randomly keep placing models on a map then it would be an unsolvable maze (atleast 80% of the time if I am sure).

As for the algorithms there are different ones, one of the maze generation algorithms I have known about is, the Randomized Prim’s algorithm:

  1. Start with a grid full of walls.
  2. Pick a cell, mark it as part of the maze. Add the walls of the cell to the wall list.
  3. While there are walls in the list:
  4. Pick a random wall from the list. If only one of the two cells that the wall divides is visited, then:
    1. Make the wall a passage and mark the unvisited cell as part of the maze.
    2. Add the neighboring walls of the cell to the wall list.
  5. Remove the wall from the list.

@Kamlkaze_Kid This isn’t something that random part generations will do the work, because he wants to create a random maze but it also needs to be solvable.


Okay, so what would be easier?
Pre-made models or algorithms?
Cause traps would be harder todo with algorithms if not mistaken.

Random is not hard, the problem is ensuring you can get from the start to the end.

A bit map for NxN rooms is 2*N*(N+1) bits
(Each bit being a wall.)
Or if you assume each exterior wall is existent it is 2*N*(N-1)
The second lets you make a 5x5 map from just a single 32bit random number

Try to explain without picture

So for a simple map you draw 2x2 boxes
the top wall there are 2, for the side walls of the top two boxes there are 3, the bottoms have 2 and then 3 then 2 again.

each of your models has a bit map,
1110 for the single entrance
1010 for the straight path
1100 for the corner
1000 for the 3way
0000 for 4way
Edit: you can’t check these directly, so it can get fuzzy

You just check which one to use and rotate to fit.

After that you can manually check for a good path and make one if there isn’t

Edit2: This lets you effectively have a seed to regenerate a maze if you want to have two people compete in times or just re-challenge. Just need to make sure your path solver is consistent.

1 Like

It will be hard, but Algorithms are a good one to go with because if you want to make the maps unique and random all the time then the algorithms will be the only things that work out in this case.

But if you can make about like 5-6 different maps, its not that bad either, its just that once a player has played all those combinations of maps they might get bored. And it wont be random after that anymore, I believe.