How should I handle loading maps?

I’m working on a round based game that’ll have a different map each round.
I’m trying to decide the best method to do for loading maps.

I have searched for similar posts but couldn’t find a definite answer.

So far the methods I have come up with are:

  1. Clone the Map from ReplicatedStorage to the Workspace
  2. Clone the Map from ServerStorage to the Workspace
  3. Clone the children of the Map from ReplicatedStorage to the Workspace
  4. Clone the children of the Map from ServerStorage to the Workspace

I’m uncertain as to which method is the most efficient, which should I use?

Someone also mentioned just parenting the map from Replicated/Server Storage which I could do as the map will be the same when the round ends as when the round started; but is there any negatives for doing this?

12 Likes

I would rule out cloning out map children almost immediately because those methods don’t at all seem favourable for a use case involving maps whatsoever. Even if you need to explicitly handle objects, cloning the entire map is far more “efficient” and manageable.

If you need the map to replicate to the client and allow it’s assets to be readily available (as in you care about aesthetic), then you’re probably looking for ReplicatedStorage. If the map only needs to be accessible by the server (in terms of handling) and how instantly the client downloads associated assets doesn’t matter, then place it in ServerStorage (network traffic is also reduced this way).

Personally, I don’t parent in and out of a storage service, even if it’s just a one-time thing. If I’m going to add a map, then I’d like it to be the absolute freshest and pristine it can be. If any part of the map is modifiable, parenting in and out of services is not going to fair out well for you. Even then; parenting a clone of a map and parenting between services has a negligible time difference, so it’s up to preference at that point.

9 Likes

ServerStorage and RepletedStorage have their advantages and disadvantages.
ServerStorage: - I would put the maps here.
The wiki says: “By storing large objects such as maps in ServerStorage until they are needed, network traffic will not be used up transmitting these objects to the client when they join the game.” This means the map is stored their until needed and isn’t ‘loaded in’ when the client joins the game.

ReplicatedStorage
ReplicatedStorage Replicates the objects onto the client when they join the game so it may take longer for the clients to load it. Replicated storage is an ideal place for remote events and module scripts. Here is the quote from the wiki page:

“ReplicatedStorage is a container whose contents are replicated to all connected clients, allowing such objects to be stored until needed. ReplicatedStorage is also an ideal location for RemoteFunction|RemoteFunctions and RemoteEvent|RemoteEvents since they can be found on both the client and server.”

Cloning
I would clone the maps as if one map gets messed up like something has been deleted when it is in use, it doesn’t matted as such because their will be a fresh copy of the map in ServerStorage or ReplicatedStorage.

3 Likes

I would store the map in ServerStorage if it is big, if the player needs data like a image of the map, map name, etc I would send it to the client with a remote or have the map image and name display on a surface gui on the server.
To load a map I would simply using a ipairs loop, cycle through all models (if the map is split in seperate models) and clone each model one by one with a 1/4 second delay between each clone to the workspace (or where you want the map).

Kinda like this.

local maps = game.ServerStorage.Maps:GetChildren()
local chosenmap = maps[math.random(1, #maps)]

print("Loading the map...")
for k, v in ipairs(chosenmap:GetChildren()) do
 v:Clone().Parent = workspace.CurrentMap
 wait(0.1) --A small delay to make it less laggy.
end
print("Map loaded.")

To unload the map simply do
workspace.Currentmap:ClearAllChildren()
That’s my way of doing it.
Hope that helps.

32 Likes

By far the best method (that I have never run into problems with) is to load the map in piece-by-piece with a for loop. This is faster than just cloning the map into Workspace and doesn’t create a giant lag spike when the map loads.

In addition to this, to prevent players from falling through the map, I locally set each player’s gravity to 0 before teleporting them. I then set it back to normal once the map has loaded for them.

6 Likes

I’m in complete agreement with those mentioning you should load in the map piece by piece as opposed to just hoping the client can handle loading in the whole map in one go.

As an additional security step, I would have some method of communicating to the clients that the map has been loaded in. If you’re executing things on the client then it’s recommended you wait until the server notifies the client to run those scripts.

1 Like

As with intended_pun’s reply I would have all maps in the ServerStorage to reduce memory, processor and network usage. Unless you need all the maps loaded in at start, having them in ServerStorage is definitely the best alternative.

Load the map in piece by piece so the clients won’t get met with a huge lag spike.

How do you detect when the map has loaded?

2 Likes