Passing instances from server storage to client with remote function

Not really sure, but it’s a string, it’s not an instance, you can’t do anything with it. It is worth testing, try to send an instance from the client to the server and see the result.

RemoteFunction:OnServerInvoke = function(player)
local Data = {}
Data[Instance.Name] = Instance
return Data
end

Does this will worked?

nil means that there is nothing there. It will return nil because the client cannot access it.
It has to exist on both server and client.

Example:
Server

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

Event:FireAllClients(instance, instance.Name)

Client

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

Event.OnClientEvent:Connect(function(Object, ObjectName)
	print(type(Object)) --> nil
	print(ObjectName) --> instance, because it is a string
end)

I’m using remote function in this case, what’s the purpose of string that passed to client?

There can be a purpose if you want it to be, but you cannot send instances, as I showed you above.
You’ll need to find another solution that both the client and server has access to.

I said if it’s sent as a key inside of a dictionary, if you sent something like

Event:FireAllClients({[instance] = true})

and looped through the dictionary in the client

Event.OnClientEvent:Connect(function(dict)
	for i, v in pairs(dict) do 
       print(i, v) -- <instance> something true, I think
    end
end)

perhaps I’m wrong about this.

And it is possible to send instances after doing some work.

The index will be nil, value will be true
In other words: nil = true.

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.