I have wrote a script from a Roblox tutorial and it looks correct, rooms are overlapping a lot though…
Full script:
local Seed = tostring(math.random(1, 1000000))
local CurrentNum = 1
local RoomsLimit = 100
local GeneratorDelay = true
print(Seed)
local function rarityFunction(Rooms)
local totalWeight = 0
local roomTable = Rooms:GetChildren()
for _, room in pairs(roomTable) do
totalWeight += room.Rarity.Value
end
local random = Random.new(tonumber(string.sub(Seed, CurrentNum, CurrentNum)))
local rnd = random:NextNumber(0, totalWeight)
for RoomNum, room in pairs(roomTable) do
if rnd < room.Rarity.Value then
return RoomNum
end
rnd -= room.Rarity.Value
end
return 1
end
function generateRoom(ConnectPoint)
if #workspace.Rooms:GetChildren() < RoomsLimit and ConnectPoint and #workspace.RoomsAssets:GetChildren() > 0 then
repeat task.wait() until GeneratorDelay
local PointCFrame = ConnectPoint.CFrame
ConnectPoint:Destroy()
local newRoom = workspace.RoomsAssets:GetChildren()[rarityFunction(workspace.RoomsAssets)]
local newClonedRoom = newRoom:Clone()
newClonedRoom.Parent = workspace.Rooms
local TouchConnection = newClonedRoom.Hitbox.Touched:Connect(function()end)
--math.randomseed(tonumber(string.sub(Seed, CurrentNum, CurrentNum)))
local SelectedPointIndex = math.random(1, #newClonedRoom.Connections:GetChildren())
local SelectedPoint = newClonedRoom.Connections:GetChildren()[SelectedPointIndex]
local SelectedPoints = newClonedRoom.Connections:GetChildren()
CurrentNum += 1
if CurrentNum > #Seed then
math.random(tonumber(Seed))
Seed = tostring(math.random(1, 1000000))
CurrentNum = 1
end
table.remove(SelectedPoints, SelectedPointIndex)
newClonedRoom.PrimaryPart = SelectedPoint
newClonedRoom:PivotTo(PointCFrame * CFrame.new(0, 0, -1) * CFrame.Angles(0, math.rad(180), 0))
newClonedRoom.PrimaryPart:Destroy()
for _, Part in pairs(newClonedRoom.Hitbox:GetTouchingParts()) do
if not Part:IsDescendantOf(newClonedRoom) then
newClonedRoom:Destroy()
newClonedRoom = nil
local deadEnd = script.DeadEnd:Clone()
deadEnd.Parent = workspace.DeadEnds
deadEnd.CFrame = PointCFrame
break
end
end
TouchConnection:Disconnect()
if newClonedRoom then
if newRoom.RoomLimit.Value > 0 then
newRoom.CurrentRoomNum.Value += 1
if newRoom.CurrentRoomNum.Value >= newRoom.RoomLimit.Value then
newRoom.CurrentRoomNum.Value = 0
newRoom.Parent = workspace.UsedRooms
end
end
end
if newClonedRoom then
GeneratorDelay = false
for _, Point in pairs(SelectedPoints) do
task.spawn(function()
generateRoom(Point)
end)
end
GeneratorDelay = true
end
elseif ConnectPoint then
local NewDeadEnd = script.DeadEnd:Clone()
NewDeadEnd.Parent = workspace.DeadEnds
NewDeadEnd.CFrame = ConnectPoint.CFrame
print("Generation done!")
end
end
generateRoom(workspace.StartPoint)