I'm having a problem with loading a map from replicatedstorage to workspace

So, what I’m currently trying to do is a loading a map from replicatedstorage to workspace, because I heard there are benefits on loading maps that way. I’m doing this because many people have reported lag from the map. Even mobile users.
Here if you have to know how many parts/meshes/unions are in the map.
— COMPLETE —
Parts: 83349
Meshes: 1720
Unions: 2992
Total: 88061

Though the issue is, the maps aren’t even fully loaded, I see that It’s missing some parts, this is probably due to streamingenabled being enabled or something, because It’s not even fully loaded. I’ve tried many things to prevent that but it doesn’t seem to do anything.

I’ve tried PreloadAsync, waitforchild(), even waitforchild my player’s head, but doesn’t seem to work…
This is what I’ve got so far:

game.Workspace:WaitForChild("Map").Parent = game.ReplicatedStorage 

local players = game:GetService('Players')

local localplayer = players.LocalPlayer
local char = localplayer.Character or localplayer.CharacterAdded:wait()
repeat wait() until char:WaitForChild("Head") 
 
spawn(function()
	game:GetService('ContentProvider'):PreloadAsync({workspace,game:GetService('ReplicatedStorage'),game:GetService('PlayerGui')})
end)
 
print("loading done")
--
local newMap = workspace.Maps

local selectedMap = game.ReplicatedStorage.Map
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)

Thanks very much in advance!

3 Likes

Are you getting any message on your output window?

Everything works good, It’s just the map doesn’t even seem fully loaded after Clone(). I’m assuming that’s streamingenabled, any sollutions?

I don’t think there are any actual benefits to loading the map this way. Streaming should take care of only loading some of the map.

If you want to decrease lag you should either reduce the part count, especially in dense areas; or reduce the streaming target radius.

1 Like