This is the script I used into this video tutorial:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | print("Hello world! Maze script!") local h = 4 -- this will create a line between the parts, leaving a gap function addLine(x1, y1, x2, y2) if (x1 ~= x2) or (y1 ~= y2) then local line1 = string.format("Values for line: x1=\"%s\" y1=\"%s\" x2=\"%s\" y2=\"%s\" ",x1,y1,x2,y2) print(string.format("%s",line1)) local BuildPart = Instance.new("Part",game.Workspace) --Directory of The Part BuildPart.Name = "MazePart" --Rename the part BuildPart.Size = Vector3.new(5, 1, 5) --The Size of the Part BuildPart.Position = Vector3.new(x1, h, y1) --The Position of The Part BuildPart.Anchored = true --Anchores The Part end end -- this will create the final maze function makeMaze2(rlen1, clen1, side1, x1, y1) if (rlen1 <= 1) or (clen1 <= 1) then return end local x3 = x1+side1*clen1 local y3 = y1+side1*rlen1 -- get random values for maze local r1 = math.random() local c1 = math.random() if rlen1 > clen1 then -- divide the grid into top and bottom parts. local cpos1 = math.floor(c1*clen1) local rpos1 = math.floor(r1*(rlen1-1))+1 local x2 = x1+side1*cpos1 local y2 = y1+side1*rpos1 -- draw a (horizontal) line between the parts, leaving a gap to pass through. addLine(x1,y2,x2,y2) addLine(x2+side1,y2,x3,y2) --create maze on the top part makeMaze2(rpos1,clen1,side1,x1,y1) --create maze on the bottom part makeMaze2(rlen1-rpos1,clen1,side1,x1,y2) else -- divide the grid into left and right parts. local cpos1 = math.floor(c1*(clen1-1))+1 local rpos1 = math.floor(r1*rlen1) local x2 = x1+side1*cpos1 local y2 = y1+side1*rpos1 -- draw a (vertical) line between the parts, leaving a gap to pass through. addLine(x2,y1,x2,y2) addLine(x2,y2+side1,x2,y3) --create maze on the left part makeMaze2(rlen1,cpos1,side1,x1,y1) --create maze on the right part makeMaze2(rlen1,clen1-cpos1,side1,x2,y1) end end -- this is the final maze for makeMaze2 function makeMaze1(rlen1, clen1, side1, gap1) local x1 = side1*gap1 local y1 = side1*gap1 local x3 = x1+side1*clen1 local y3 = y1+side1*rlen1 addLine(x1,y3,x3,y3) addLine(x1,y1,x3,y1) addLine(x1,y1,x1,y3-side1) addLine(x3,y1+side1,x3,y3) makeMaze2(rlen1,clen1,side1,x1,y1) end --You can use math.randomseed to seed the pseudo-random number generator for a --different seed results in a different maze. math.randomseed(12346) local rlen1 = 7 local clen1 = 6 -- I used size with (5, 1, 5) let set to 4 local side1 = 5 -- the position from the (0, 0, 0) , see x1 = side1*gap1 local gap1 = 1 makeMaze1(rlen1,clen1,side1,gap1) |