Passing instances from server storage to client with remote function

Did you try the code? If so, that interesting. I remember getting similar results, unless it’s something else.

I’m no good at HTTPS service. 30 characters

Nothing involves Http service here. It’s just using remote events, which you’ll get around after some experience.

I know how to pass data on remote event and function, but passing instances idk.

Server

local Event = game:GetService('ReplicatedStorage').Event
local instance = game:GetService('ServerStorage').instance

local Dict = {instance = true}

Event:FireAllClients(Dict)

Client

local Event = game:GetService('ReplicatedStorage'):WaitForChild('Event')

Event.OnClientEvent:Connect(function(Dict)
	for index, value in pairs(Dict) do
		print(index, value) -- index = string (instance's name), value = boolean (true)
	end
end)

As we told you multiple times, it’s not possible. You also can’t pass things like Vector3s and CFrames (userdatas). You need to serialize them, and send them over, then deserialize them.

So I should put the temporary model on replicated storage or anything else that not visible to player but accessible.

ReplicatedStorage is a good solution for your project.

1 Like

I’ll clone the temporary models to replicated storage then when voting ends should I delete them after?

Do that, and yes, if they are no longer needed, call :Destroy() on the model(s).

Since I know how to sort things, maybe that’s the solution of my problem.

Thanks to everyone who tried their best to help me out :grin::sparkling_heart:

1 Like

image
It shows both <Instance> and the instance’s name.

I’ll try that too! :smile::+1:t2:

30 characters.

I’m currently on mobile.
30 characters

That is incorrect, as the index is a string, and the value is a boolean.

print(type(index), type(value)) -- string boolean

Instances are passed by reference.
Objects created on the client cannot be seen by the server, so the reference will be nil.
Vice versa.

Please read everything before you comment, as I mentioned:

Instances are passed by reference.
Objects created on the client cannot be seen by the server, so the reference will be nil.

Vice versa, meaning the opposite of what I explained.
Server → Client, Client → Server.

1 Like

I just showed you the output? You are printing the key’s (it’s not an index) type, and not the key itself. What I’m saying is, if an instance is passed as a key inside of a dict, it’s not nil, it’s <Instance> the instance's name, which is a string obviously.

Also passing by reference has no relation to this? Passing by reference or by value is how passed arguments to a function are handled.

What things are remote function allowed to be passed to client?

If you need to privately replicate an instance, you can parent it to player.PlayerGui, fire a RemoteEvent, then
immediately parent it back to nil. This isn’t documented, but my entire game relies on it for streaming data/modules as needed. For a simple round-based game, ReplicatedStorage would work though. I would recommend just uploading images though, as they will have better quality and performance.

5 Likes