The maze algorithm I made generates large amounts of instances once the maze is fully created. It iterates through every node and spawn the wall based on the information. Is there a way to generate large amount of instances without crashing? I also want to make the speed of the maze generation fast enough while not crashing the server. I didn’t find any dev forum posts that could help me. Is it impossible? Thanks for helping!
for i, Node in ipairs(MazeGenerator.Nodes) do
Node:SpawnWalls()
end
:SpawnWalls() method
function NodeClass:SpawnWalls()
local MazeService = Knit.GetService("MazeService")
local StartingVector = MazeService:GetConfigurations().StartingVector
local CellSize = MazeService:GetConfigurations().CellSize
local Height = MazeService:GetConfigurations().Height
local Thickness = MazeService:GetConfigurations().Thickness
local Material = MazeService:GetConfigurations().Material
local Model = Instance.new("Model")
Model.Name = self.X .. ", " .. self.Y
local MiddlePoint = Vector3.new(StartingVector.X + CellSize * self.X, StartingVector.Y - (Height / -2), StartingVector.Z + CellSize * self.Y)
self.Position = MiddlePoint
for Index,_ in pairs(self.Walls) do
local Wall = Instance.new("Part")
Wall.Anchored = true
Wall.Material = Material
if Index == "Up" then
Wall.Position = Vector3.new(MiddlePoint.X - CellSize / 2, MiddlePoint.Y, MiddlePoint.Z)
Wall.Size = Vector3.new(CellSize,Height,Thickness)
end
if Index == "Down" then
Wall.Position = Vector3.new(MiddlePoint.X - CellSize / 2, MiddlePoint.Y, MiddlePoint.Z - CellSize)
Wall.Size = Vector3.new(CellSize,Height,Thickness)
end
if Index == "Left" then
Wall.Position = Vector3.new(MiddlePoint.X - CellSize, MiddlePoint.Y, MiddlePoint.Z - CellSize / 2)
Wall.Size = Vector3.new(Thickness,Height,CellSize)
end
if Index == "Right" then
Wall.Position = Vector3.new(MiddlePoint.X, MiddlePoint.Y, MiddlePoint.Z - CellSize / 2)
Wall.Size = Vector3.new(Thickness,Height,CellSize)
end
Wall.Name = Index
Wall.CanTouch = false
Wall.CanQuery = false
Wall.Parent = Model
end
local TopWall = Instance.new("Part")
TopWall.Transparency = 1
TopWall.Material = Material
TopWall.Anchored = true
TopWall.Size = Vector3.new(CellSize, Thickness, CellSize)
TopWall.Position = Vector3.new(MiddlePoint.X - CellSize / 2, MiddlePoint.Y + Height / 2, MiddlePoint.Z - CellSize / 2)
TopWall.Name = "Top"
TopWall.CanTouch = false
TopWall.CanQuery = false
local BottomWall = Instance.new("Part")
BottomWall.Material = Material
BottomWall.Anchored = true
BottomWall.Size = Vector3.new(CellSize, Thickness, CellSize)
BottomWall.Position = Vector3.new(MiddlePoint.X - CellSize / 2, MiddlePoint.Y - Height / 2, MiddlePoint.Z - CellSize / 2)
BottomWall.Name = "Bottom"
TopWall.CanTouch = false
TopWall.CanQuery = false
TopWall.Parent = Model
BottomWall.Parent = Model
Model.Parent = MazeModel
end```