How to load and unload parts and maps?

I am working on something where the map has these sub-maps, regions, zones, like a game where everyone has their own island. And when a player teleport from one island to another it unloads the previous island and loads the new island.
The problem is that I can’t figure out how to unload the parts, where do they go when they “unload”. It seems to be a common system but from the posts I’ve read, I get conflicting answers.

5 Likes

You could move them to ReplicatedStorage or ServerStorage.

2 Likes

Likely the easiest way to do this is to let the roblox engine handle it automatically through content streaming, otherwise known as “StreamingEnabled”. Check that link for more information but to basically all clients are only sent the information (regions) of the world (Workspace descendants) nearest to their characters (by default). This could create the effect of loading and unloading islands while simultaneously providing an assortment of performance benefits to clients.

Be aware though that client code will have to handle cases where something they want to access isn’t currently streamed to its particular client.

2 Likes

The thing is that the client can’t access ServerStorage, if a server script is parenting the previous zone to ServerStorage the zone will be gone for all the players using that zone not just the player leaving it, and I’ve seen people suggest using ReplicatedStorage but people are also saying not to use it because it replicates to all clients which is the conflicting answers thing that I can’t get over.

2 Likes

I’m trying to make my own content streaming that’s more direct and manageable, like what if I need to stream out something that is too close or stream in something that’s too far, or stream out something but keep this other thing that’s the same distance. Putting a specific thing out for a specific player and putting a specific thing away for a specific player, is there any way?

2 Likes

Then use ReplicatedStorage, which, as the name suggests, will be replicated from server to client.

2 Likes

But what about the replicating to all clients part? Wouldn’t that be an issue?

1 Like

If you want to be able to go between player islands and have it be completely private, you can use ReservedServers via TeleportService

1 Like

Yes, there are ways to do these sorts of things and they are explained in the linked article, but it may not be as “direct” as you are looking for. You can force a Model to be persistent per player (Model:AddPersistentPlayer()), meaning that client will never stream it out. You don’t have as direct of control over forcing things to stream out, but typically you wouldn’t want to stream something out manually anyways.

1 Like

PersistentPerPlayer assumes that non-persistent players will be atomic, meaning it can still be streamed in.

1 Like

But what if I just want to put away or load models and not take a player to a whole different server where he’ll be separated from the players he was playing with?

1 Like

Then you would parent the models to ReplicatedStorage/ServerStorage, or use StreamingEnabled as @East98 stated above.

1 Like

But what would I be doing if doing it manually is exactly what I want?

1 Like

Yes but all of those methods seem to have just as many reasons why they can’t be used as I’ve mentioned.

1 Like

Why couldn’t you use ReplicatedStorage?

1 Like

If you are okay with different parts existing on the server and client, you can parent your maps and parts to workspace.Camera. When you want a player to load a map clone it to their PlayerGui. Then, have that player parent the map in their PlayerGui to workspace.

1 Like

Oh yeah, forgot about the camera trick.

1 Like

Because the majority of people discussing this sort of thing are against it and now I feel unsure

1 Like

If you want to manually stream models in and out without using StreamingEnabled then you could:

  1. have to write a whole client-side service that either moves models to and from ReplicatedStorage or
  2. Reinvent the wheel with a manual streaming service where clients requests (or server detects) information from the server about a particular region constructs some sort of packet/intermediate form and sends this to the client who reconstructs the region using this information.

I wouldn’t recommend either scenario as you’re not gaining much of a performance benefit in scenario 1 (actually you could be making performance worse depending on how often/how much is being streamed) and scenario 2 requires a bunch of additional work on your end that is already provided for you via the default behavior of StreamingEnabled.

Going back to your original post I can’t see a reason you would want to be manually streaming out regions outside of a minor visual effect (and StreamingEnabled would handle this anyways as long as the islands are outside the StreamingTargetRadius). Perhaps you could clarify why you want to stream in/out specific regions? If it’s performance you’re worried about I would advise you not to worry because it would be difficult or impossible to create a system that does it better than the built in StreamingEnabled.

4 Likes

Why is it cloned from the camera to the PlayerGui then parented to workspace instead of directly from camera to workspace?