7z99
(cody)
July 23, 2020, 8:42pm
10
EmilyBendsSpace:
What exactly do you mean by “lag”? And on what hardware? Spawning thousands of parts is going to take time, you can’t make it instantaneous. Memory needs to be allocated, and a lot of things are being put into the collision octree. Disposing of thousands of parts isn’t instantaneous either. But the impact on players should be minimal.Some framerate drop on low-end machines as things pop into existence, sure, but again, that’s also to be expected.
By lag I mean FPS, going between 1 and 0 for ~20 seconds. I’m on Macbook Air 2017 but it’s pretty new (Christmas of 2019), it is extremely laggy for my friends, who also have average devices, so if a device most players have can’t handle it, I should look for some form of optimization.
(cc @B_rcode on this too)
Part of the reason my module works is because the parts have already been created. PartCache will lag if you create a new cache with 1K+ parts just as your script here does.
For optimization you could see about splitting the map into chunks.
Consider this:
local originalMap = ServerStorage.Maps:FindFirstChild(chosenMap)
local map = Instance.new("Model")
map.Name = originalMap.Name
map.Parent = workspace.Maps
-- And in some loader code:
local mapChildren = originalMap:GetChildren()
for index = 1, #mapChildren do
mapChildren[index]:Clone().Parent = map
if index % 150 == 0 then wait() end -- Every 150 parts, give this loop some breathing room.
end
This is what @cjjdawg meant in Reply #1 . The map may be one model, but you need to clone it by the model’s children in sections.
I will try this after. Thank you!