So I have a map generation system. The way it works is by having a folder in workspace with 2040 parts.
A “inpairs” loop will go thru the entire folder and will select a random room and place it on the part. (Like SCP 3008)
The Issue: My issue is if I don’t put any wait the script will get exhaustion time and the entire loop will stop therefor making a huge hole in my map.
I tried to fix this by putting a Wait() and even tho this worked on the Exhaustion problem it came with another problem that was totally unexpected. Some parts wasn’t rendering. By that I mean that part was there and could be picked up but it wasn’t rendering. (Basicly like the part was sat to Transparency = 1)
Video Incase you don’t know what I mean by rendering:
To me this makes no sense. Why would a wait() Stop some parts(Parts from the rooms) from rendering then all it does it making the loop not instant?
If you know how to fix this or have an idea please reply as I have been struggling with this for 6 hours now. even my friend with 4 years experience of lua cant figure it out.
This isn’t the entire code this is just the function of it. (If you want the entire code tell me)
local folder = game.Workspace.SpawnPartsClean:GetChildren()
--settings().Studio.ScriptTimeoutLength = -1
for i, v in pairs(folder) do
wait() -- THIS IS THE WAIT THAT MESSES IT ALL UP
--// Variables
local rooms = game.ReplicatedStorage.RoomsClean:GetChildren()
local randomroom = rooms[math.random(1, #rooms)]:Clone()
end
Well if if it isn’t rendering maybe clear the other ones that aren’t used in the room right now, you should just be able to move it to replicated storage or server storages so the ones in the room are able to render.
Okay well can you can try reloading it again to see what happens, or make it when the player loads in take a bit longer so it can load everything in properly. Also have you tried looking at everything through the server to see if it everything loaded in the server?
I have tried to reload it many times this happens each time I rejoin or something, Weridly enough tho it doesn’t happen in studio but only ingame. Therefor I cant see if it isn’t loaded for the server. But I guess it isn’t. Because its the same parts not being loaded for everyone.
Is it the same assets every time? Are the assets that don’t render meshes/unions?
If there is some sort of pattern (a few specific assets that refuse to render) then try just placing them in the workspace and seeing if they only fail to render when placed by the script or if they fail either way.
Try doing the first option I mentioned by stalling the player loading or maybe divide it into sections using a table to try and get the parts and then divide it into multiple parts so that the script can easily do the other parts once the first part is done loading.
local folder = game.Workspace.SpawnPartsClean:GetChildren()
--settings().Studio.ScriptTimeoutLength = -1
local RunService = game:GetService("RunService")
local Table = {} -- with all the selected parts
local rooms = game.ReplicatedStorage.RoomsClean:GetChildren()-- move this because the amount will not change
for i, v in pairs(folder) do
local randomroom = rooms[math.random(1, #rooms)]:Clone()
table.insert(Table,randomroom)
RunService.Stepped:Wait()
end
-- After this will divide the sections
for i=1, math.ceil(#Table/2) do
local v = Table[i]
local newroom = v:Clone()
table.remove(Table,i)
end
-- Second section
for i=1, (#Table/2) do
local v = Table[i]
local newroom = v:Clone()
table.remove(Table,i)
end
Its not the same everytime is 100 % random. And no its not meshes / unions. And there isn’t any pattern at all. If you want a closer look here’s the game: (7) SCP Foundation 9 - Roblox
I don’t believe it’s the wait(), I think it’s just that without the wait it would’ve thrown an error before the unrendered parts would occur. Not sure though.
Nah it is the wait(). If i don’t put it there’s a 50 / 50 chance the map will have hole because of script exhaustion. But none of the rooms will be missing parts (Even if it loads entire map without getting exhaustion). Its only when I use wait() then you get back on PC you will realise that its almost in every room that stuff is missing. when you go to a room you will find some white boxes appearing if you hold “E” on them you will pick it up and it will for some reason render.
Also it almost renders entire map if I don’t put a wait() Theres only 2 reason I want the wait()
If I don’t use it the first player to join will get a huge lag spike,
There isn’t any chance of a hole that fills 1 / 4 of the map.