Its basically the title, but I’ll give you some more insight.
The code is supposed to for every connection point a model has generate a dedicated (random) room for it, and then destroy the point. And with all of that said, it doesn’t work. Anyone know why?
script located in serverscriptservice:
local roomsLimit = 100
local GenerateDelay = true
local RoomsGenerating = 0
local CurrentNum = 1
--Setups
--+ Changeable
local MaximumRooms = 100
local MinimumRooms = 1
local function RarityFunction(Rooms)
local Weight = 0
for _, Room in pairs(Rooms:GetChildren()) do
Weight += Room.Rarity.Value
end
local randomWeight = Random.new():NextInteger(1, Weight)
local currentWeight = 0
local randomRoom = nil
for i, Room in pairs(Rooms:GetChildren()) do
currentWeight += Room.Rarity.Value
if randomWeight <= currentWeight then
randomRoom = workspace.GasPipeRooms[i]
break
end
end
end
local function GenerateRoom(PrevRoom)
for i, v in pairs(PrevRoom.Connections:GetChildren()) do
local randomRoom = RarityFunction(workspace.GasPipeRooms)
local newRoom = randomRoom:Clone()
local SelectedPoints = newRoom.Connections:GetChildren()
local points = PrevRoom.Connections:GetChildren()
local SelectedPoint = points[math.random(1, #points)]
newRoom.PrimaryPart = SelectedPoint
newRoom.Parent = game.Workspace.GeneratedRoomsFolder.GeneratedGasPipeRooms
newRoom:PivotTo(SelectedPoint.CFrame)
SelectedPoint:Destroy()
end
end
local PrevRoom = game.Workspace.GeneratedConcreteTunnels.Connector:WaitForChild("RightGeneration")
for i=1,50 do
GenerateRoom(PrevRoom)
end
please add prints so you can know at which part of the code it stops, also try using this:
local roomsLimit = 100
local GenerateDelay = true
local RoomsGenerating = 0
local CurrentNum = 1
-- Setups
local MaximumRooms = 100
local MinimumRooms = 1
local function RarityFunction(Rooms)
local Weight = 0
for _, Room in pairs(Rooms:GetChildren()) do
Weight += Room.Rarity.Value
end
local randomWeight = Random.new():NextInteger(1, Weight)
local currentWeight = 0
local randomRoom = nil
for i, Room in pairs(Rooms:GetChildren()) do
currentWeight += Room.Rarity.Value
if randomWeight <= currentWeight then
randomRoom = Room
break
end
end
return randomRoom
end
local function GenerateRoom(PrevRoom)
if RoomsGenerating >= roomsLimit then
return
end
for i, v in pairs(PrevRoom.Connections:GetChildren()) do
local randomRoom = RarityFunction(workspace.GasPipeRooms)
if randomRoom then
local newRoom = randomRoom:Clone()
local SelectedPoints = newRoom.Connections:GetChildren()
local points = PrevRoom.Connections:GetChildren()
local SelectedPoint = points[math.random(1, #points)]
newRoom.PrimaryPart = SelectedPoint
newRoom.Parent = game.Workspace.GeneratedRoomsFolder.GeneratedGasPipeRooms
newRoom:PivotTo(SelectedPoint.CFrame)
SelectedPoint:Destroy()
RoomsGenerating += 1
if RoomsGenerating >= roomsLimit then
return
end
end
end
end
local PrevRoom = game.Workspace.GeneratedConcreteTunnels.Connector:WaitForChild("RightGeneration")
for i = 1, 50 do
GenerateRoom(PrevRoom)
end
local roomsLimit = 100
local GenerateDelay = true
local RoomsGenerating = 0
local CurrentNum = 1
-- Setups
local MaximumRooms = 100
local MinimumRooms = 1
local function RarityFunction(Rooms)
local Weight = 0
for _, Room in pairs(Rooms:GetChildren()) do
Weight += Room.Rarity.Value
end
local randomWeight = Random.new():NextInteger(1, Weight)
local currentWeight = 0
local randomRoom = nil
for i, Room in pairs(Rooms:GetChildren()) do
currentWeight += Room.Rarity.Value
if randomWeight <= currentWeight then
randomRoom = Room
break
end
end
return randomRoom
end
local function GenerateRoom(PrevRoom)
print("1")
if RoomsGenerating >= roomsLimit then
return
end
print("2")
for i, v in pairs(PrevRoom.Connections:GetChildren()) do
print("3")
local randomRoom = RarityFunction(workspace.GasPipeRooms)
print("4")
if randomRoom then
print("5")
local newRoom = randomRoom:Clone()
print("6")
local SelectedPoints = newRoom.Connections:GetChildren()
print("7")
local points = PrevRoom.Connections:GetChildren()
print("8")
local SelectedPoint = points[math.random(1, #points)]
print("9")
newRoom.PrimaryPart = SelectedPoint
print("10")
newRoom.Parent = game.Workspace.GeneratedRoomsFolder.GeneratedGasPipeRooms
print("11")
newRoom:PivotTo(SelectedPoint.CFrame)
print("12")
SelectedPoint:Destroy()
print("13")
RoomsGenerating += 1
print("14")
if RoomsGenerating >= roomsLimit then
print("15")
return
end
end
end
end
print("16")
local PrevRoom = game.Workspace.GeneratedConcreteTunnels.Connector:WaitForChild("RightGeneration")
print("17")
for i = 1, 50 do
GenerateRoom(PrevRoom)
print("18")
end
local roomsLimit = 100
local GenerateDelay = true
local RoomsGenerating = 0
local CurrentNum = 1
-- Setups
local MaximumRooms = 100
local MinimumRooms = 1
local function RarityFunction(Rooms)
local Weight = 0
for _, Room in pairs(Rooms:GetChildren()) do
Weight += Room.Rarity.Value
end
local randomWeight = Random.new():NextInteger(1, Weight)
local currentWeight = 0
local randomRoom = nil
for i, Room in pairs(Rooms:GetChildren()) do
currentWeight += Room.Rarity.Value
if randomWeight <= currentWeight then
randomRoom = Room
break
end
end
return randomRoom
end
local function GenerateRoom(PrevRoom)
print("1")
if RoomsGenerating >= roomsLimit then
return
end
print("2")
for i, v in pairs(PrevRoom.Connections:GetChildren()) do
print("3")
local randomRoom = RarityFunction(workspace.GasPipeRooms)
print("4")
if randomRoom then
print("5")
local newRoom = randomRoom:Clone()
print("6")
local SelectedPoints = newRoom.Connections:GetChildren()
print("7")
local points = PrevRoom.Connections:GetChildren()
print("8")
local SelectedPoint = points[math.random(1, #points)]
print("9")
newRoom.PrimaryPart = SelectedPoint
print("10")
newRoom.Parent = game.Workspace.GeneratedRoomsFolder.GeneratedGasPipeRooms
print("11")
newRoom:PivotTo(SelectedPoint.CFrame)
print("12")
SelectedPoint:Destroy()
print("13")
RoomsGenerating += 1
print("14")
if RoomsGenerating >= roomsLimit then
print("15")
return
end
end
end
end
print("16")
local PrevRoom = game.Workspace.ConnectorRoom.Connector
print("17")
for i = 1, 50 do
GenerateRoom(PrevRoom)
print("18")
end
First of all, the room is nowhere to be found even tho the output says otherwise
Second, the output first prints 1 & 2 but after the first generation function is ran then 1 & 2 isn’t outputed but instead the function starts from 3 and so on.
Edit: 3 was maybe outputed because the if statement wasn’t correct and it reset, but then it jumps from 14 to 18, and no room is found anywhere