Send Server Instance to Single Client

Hello, All,

I’m working a project with a lot of assets, all of which utilize external data (decals, meshes, etc.), and many of which may never be used in a given play session. As a result, I want to store them on the server and only replicate them to the client when a client needs those assets. That said, I’m struggling to figure out a stream-lined method of sending an instance to a single client without having to send it to all clients.

A method that I know would work but would like to avoid would be to transform requested assets into tables of instances/properties that would then be sent via a RemoteEvent that the client could then reconstruct. The reason I’m worried about this is that it isn’t inherently future-proof.

I have tried creating folders for each player in ReplicatedStorage and having each client destroy the folders that don’t belong to them, but items inserted into other clients’ folders still replicate to the other clients even though the original clients’ folders aren’t accessible anymore.

Is there a more elegant solution that I’m missing?

1 Like

I’m pretty sure that if you return an object through a RemoteFunction then it will be replicated to the client. (I could be wrong/this could have changed).

A hacky way of doing it could be to place the object inside the Player’s PlayerGui and then locally reparent from there; since this only replicates to each player individually.

2 Likes

You know what, hacky works for me. Transfering the assets/clones of the asset through RemoteEvents doesn’t seem to work because the original asset is not visible to the client.

2 Likes

RemoteEvents only pass on references to that instance; if you were to put a tool in ServerStorage and tell the client about it, the client would just recieve nil. However, if you were to put that tool into ReplicatedStorage (As the service name implies, it replicates), it will not be nil.

How did this go? I’m thinking of trying out this method myself — transferring things from the server to a single client by putting things in the player’s PlayerGui. This does seem like a pretty hacky way of doing things, and I wonder if there’s any other alternative to this.

While the project that prompted this question didn’t make it to release, I have used this process in another project where I needed the server to generate objects so that I could keep information away from the client, and it worked well. The only sticking point is making sure to wrap objects in a ScreenGui with ResetOnSpawn set to false, otherwise the server will destroy everything when the player resets. You might be able to get around that by having the server reparent objects after the client processes them, but I haven’t experimented with that.

It should be mentioned in retrospect that using this method for pure asset delivery would only really be necessary for MeshParts since they can’t be created from scratch, so to speak.