I suggest making the rooms no bigger than (20,15,20). I once made a backrooms game that generated about 1600 ‘rooms’. It didn’t lag until I made it generate one row at a time.
I see from your code that you made row-length cells and you’re generating it really quickly too.
So uh. Chop up the room a bit and yeah, you’ll be a bit better off I think.
local Size = 20 --Room must be square. Change this size to the length or width of the room.
local rooms = game.Workspace.MapParts:GetChildren()
local startingroomnum = math.random(1, #rooms)
local startingroom = rooms[startingroomnum]
local startpart = game.Workspace.RoomsStart
local amountToGen = 30
print(startingroom)
print("This is starting room ^^^")
local startcopy = startingroom:Clone()
startcopy.Name = "startroom"
startcopy.Parent = workspace
startcopy.PrimaryPart = startcopy.floor
startcopy:PivotTo(startpart:GetPivot())
for x = 1, amountToGen do --Added an extra loop so it generate in a square instead of a line.
for i = 1, amountToGen do
local currentroomnum = math.random(#rooms)
local currentroom = rooms[currentroomnum]
local currentclone = currentroom:Clone()
currentclone.Name = "newroom"
currentclone.PrimaryPart = currentclone.floor
currentclone.Parent = workspace
currentclone:PivotTo(startpart:GetPivot() + Vector3.new(Size*x,0,Size*i))
print(currentroom)
task.wait(0.05)
end
task.wait(0.05
end
This is what I am left with. I think it would be very inconvenient to scale down the rooms, but you helped me with another problem; making a square. Thanks for the wrong reason lol.
(Btw like this, it’s still laggy)
Edit: Okay. By removing the task.wait(0.05) It has certainly decreased the lag. After it’s generated, it’s still pretty laggy with the rooms just being there.
Oh yeah, with that complexity of a map.
For my game, each room had a sound and light but it wasn’t that laggy.
Try making as many things into a union as possible. This might help with shadow lighting lag.
First try disabling globalshadows in lighting to see if it helps.
Im pretty sure most games remove rooms that are away from you. Amount of details should be lower, for example using meshes would reduce amount of faces/edges if you havent yet, streaming enabled obviously.
I have streaming enabled. I can’t remove rooms as players are far from them because multiple players play this at the same time in very different places all around the map.
Is there a way I can reduce the render distance or something? I am looking for tutorials but they are all outdated.
Alright sure, it may not work cuz I’m typing this on my phone.
Also this should go under the “amountgen” pairs loops:
for i, room in pairs(rooms:GetChildren()) do
if room ~= rooms[currentroomnum] then
for i, part in pairs(room) do
if part:IsA(“Part”) then
part.Transparency = 1
part.CanCollide = false
else
-- Nothing here unless you wanna do smthn
end
end
end
end
Yeah it should be in a local script because if not, everyone in the rooms behind would see nothing. And it wouldn’t work anyways because this is designed to find a specific player’s current room and get rid of the rest (if there were multiple player’s, then all the rooms would be gone even if it worked.
What you should do is fire a remoteEvent to the client and paste my code in there. And then lemme know if it works or not.
Actually @Redluo is correct. StreamingEnabled doesn’t get rid of rooms, it just doesn’t render them (if the player isn’t close enough) for a specific player. Everyone else who is closer to those room will see them.