How to clone an instance to a player that will be visible to player only (ex. gui)

Hello.
I’m wondering how would I clone a GUI (or a random brick for example) to a specific player only and if that’s a GUI, it would be visible to the player only in PlayerGui, not the server.
For example, if I used :Clone from server storage to PlayerGui, that GUI would still be visible to the server.
If I put it in ReplicatedStorage for example, anyone could access it.

For buildings, how would I clone them to a client without them being visible to other players?

Thank you.

2 Likes

For the GUI, if you only clone it into the person you want to see it’s PlayerGui, it will only show up for them.

For the building, you just need to clone it via local script

Well, I know how to clone, but I dont want GUIs to appear to server and for buildings, I don’t want them to appear to other players as the only way I know to store buildings is to put them in Rep. Storage.

Wait, you don’t want the server to know that there is a cloned GUI/object, or you just want only the player you have told it to clone it to see it?

Basically, I want to clone it from server storage to player gui, but without the server seeing it

Oh okay. You will be able to clone a GUI from the server storage to the players PlayerGui, and only the player that the GUI is cloned into will see that GUI.

Now with the building, to my knowledge, you couldn’t have that in server storage, because you would want a local script to clone the building on the clients side. You would be able to achieve this by moving the building from server storage to replicated storage.

Also, just a note. Anything cloned by a local script is only seen by the player who has the local script, and it will not be seen by the server.

And just in case you have an old game, you would need to turn filter enabled on so that there is a difference between client and server.

1 Like

Thank you for your response, but I’m asking how to actually do that …

Sorry for bumping this thread, but I’m looking forward to the solution without opening a new one.

Are there any other solutions?
TL;DR: for example, how would I make a GUI (surface gui) visible to specific people only (in workspace) without putting it in replicated storage (which would make it accessible to everyone), but rather cloning it from the server side directly to the client side.

You could clone to the Player’s playerGui and make the player set the adornee of the gui, which would solve your issues with other players seeing it (as other players and the server do not see changes made by a different player’s localscripts), however (i don’t know why you wouldn’t want the server to see something) it leaves the second part out, as cloning the Gui into the player’s gui makes it “visible” on the server.
Possibly my instance to network module would help? It lets you send instances that only exist for the server to the client (server => client) or vice versa (client => server), and while it is no where near complete, it is functional. I published it here.
It isn’t optimized nor is it perfect, however it is easy to use and add more instances to the lookup table, so it works fine for things like your use case.
Hopefully this helps, PM me if you have any questions about it.

1 Like

Basically, for GUIs, I mean, when I clone a gui from the server, and if a Client closes it locally, it will still exist in the server’s side.

Use a RemoteEvent to destroy it on the server, or just clone it from the client not the server.

Clone the GUI, do not parent it, pass it as an argument via a RemoteEvent, let the client make a clone, let the server (after a short delay or after the client makes a clone) destroy its copy, then make the client put its clone in their own PlayerGui.

Okay, how would I do that so other clients don’t see it? Like, I know about Rep. Storage, but it means everyone sees it

Is this during when the server starts? If so, some code like this might work:

local GUI = game:GetService("ServerStorage").GUI:Clone()
local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(Player)
	if Player.Name == "PlayerName" or Player.UserId == 12345678 then
		GUI.Parent = Player.PlayerGui
	end
end)

If this doesn’t fit your case then I don’t really understand your question.

Thank you, but the GUI will still be visible on the server side, but I guess that’s fine. I’ll just use remote events to destroy them from client’s side.