Selective replication

I’m working on a game and in this game I’ve decided to decrease load times by populating the map with props retrieved from replicated storage on the client side. This allows me to only replicate the prop once, ever, and I can use all that saved time to make the prop much higher quality.

This, however, is a bit of a double-edged sword when it comes to mobile. The memory limit prevents me from displaying any prop that could be considered high quality, so naturally your first though is to display low-quality props instead. That, however, will not accomplish anything because the mobile client will still have the high-quality props replicated to it because there is no way to replicate something to only one client.

My solution is these API additions:

[code]NetworkServer
Method :ReplicateToClient(Player client, String title, Instance object)
Method :GetReplicatedObject(Player client, String title) -> Instance object
Event .ClientReplicated(Player client, String title, Instance object)

NetworkClient
Method :ReplicateToServer(String title, Instance object)
Method :GetReplicatedObject(String title) -> Instance object
Event .ServerReplicated(String title, Instance object)[/code]

client is the target client.
title is a string that tells the code on the other machine how to handle the object
object is the object
ReplicateToServer/Client is used to send the object to the other machine, it fires the Client/ServerReplicated event when received, and the object can then be retrieved in the future using GetReplicatedObject on the machine it was sent to.
GetReplicatedObject returns the object that was replicated using that title
Server/ClientReplicated is fired when an object is received

When an object is replicated it will only be replicated once, when you call the method. If you call the method again on the same object then the object will update, and if you use a different title the event will fire.

EDIT: Probably better solution:

8 Likes

I’m not sure if those methods would work with the way roblox replicates things but If it does, I’m with you.

You could just put the models into ServerStorage and then use a RemoteFunction to grab the models

function Get.OnServerInvoke(Player, Name)
	local Item = Assets:findFirstChild(Name, true)
	if Item then
		Item = Item:Clone()
		Item.Parent = Player.Backpack --only way to pass the Server/Client barrier
		return Item
	end
end
1 Like

Backpacks only replicate to that player? No other players can access the contents of them?

The backpack idea might do it. Thanks. Would still appreciate an official method, though.

Oh no, that’s not true.

But it would only replicated once and then do all the cloning locally though

Ethan, I gave you the backpack idea.
It will still replicated to other clients though, but just once.

That’s the thing – we don’t want it to replicate to other clients. We need it to replicate to only the target client. What if a user with a server and 2 CPUs and 8 cores + uber graphics card comes in and loads all the good stuff, and then a poor mobile user has to come in and download all that stuff because it’s in the game?

Maybe a better suggestion is a descendant of Player like Backpack or PlayerGui called TargettedStorage and it only replicates from server to that specific client, no one else can see it. This is a much more elegant solution that what I originally suggested IMO.

I was trying to think of a way to do this the other day when the thought of loading the inside of the buildings from the server came to mind. I couldn’t think of a way to replicate to a specific client, so something like this would be helpful.

Can clients call game:GetService(“InsertService”):LoadAsset(assetId)?

I suppose we could upload non-public models of the things and have the client insert them when needed.