I am currently running into an issue where when I clone a map and put it into Workspace the game stutters a bit and/or crashes low end (or mostly apple) devices. I was wondering what is the best way to load my maps in pieces, specially since all the maps are basically one model filled with parts…
In the past I’ve found putting a few wait()'s in the code can help with crashes. Loading the map in pieces could definitely work. It could be done in 3-5 lines of code. Is the map big or just super detailed? If it’s big then you may consider streaming the map in and out as the player moves across the world.
The maps vary in size, I did try streaming the maps before however that caused issues with other systems in the game.
Though loading the map in pieces is a pretty good idea, here is the code I just thought up with @BusyCityGuy
local newMap = workspace.Maps local selectedMap = game.ReplicatedStorage.Folder.Apocolypse local totalParts = 0 -- just to see how many parts i went through local function LoadMap(prt, parent) if prt:IsA("Model") then if #prt:GetChildren() > 0 then print("Model:", prt.Name, "Children:", #prt:GetChildren()) local newModel = Instance.new("Model") newModel.Name = prt.Name newModel.Parent = parent local searched = 0 for _, prtChild in pairs(prt:GetChildren()) do totalParts = totalParts+1 if searched % 300 == 0 then wait() end searched = searched + 1 LoadMap(prtChild, newModel) end end else prt:Clone().Parent = parent print("Cloned:", parent.Name) end end local t = os.time() LoadMap(selectedMap, newMap) print("Map loaded:", os.time()-t, ":", totalParts)
What I do is basically If the child I am looking at is a model I just recreate the model with Instance.new() cus cloning would take its children.
but if its not a model it’ll take a clone of the one in rep storage and parent it to the one in workspace.
I’ll have to play with the
% 300 part as I don’t want it to be super fast where it still lags and be slow where it takes ages…
But yea anyone who stumbles upon this thread feel free to use the code.