Server -> Client Communication

I’m trying to send a table of Tools from the Server to the Client, as the tools are in ServerStorage. Currently, I’m trying to do this via a RemoteFunction however the table is always returning nil on the client. Is there anyway I could do this better, I’ve tried RemoteEvents however they still are returning nil.

Many thanks,

1 Like

The client can’t see things that are in ServerStorage because it’s only meant for the server. Use ReplicatedStorage instead.

Edit: nvm I just realized you are sending a table and not actual instances. Can you show me the code?

1 Like

Can you show me your script, maybe then I can help you?

Yes that’s why I am going to get the Server to send the code to the Client. I know that already.

Server Code:

ReturnTools.OnServerInvoke = function(player)
	local tools = {}
	for _, item in pairs(ServerStorage:GetChildren()) do
		if item:IsA("Tool") then
			table.insert(tools, item)
		end
	end
	return tools
end

Client Code:

local ReturnedTable = ReplicatedStorage.TKServingSystem.ReturnTools:InvokeServer()
for _, v in ReturnedTable do
	print(_, v) -- never prints
end

Check if there is anything in the tools table in your serverscript

There is, in some previous debugging before I returned the table of tools, I iterated through the table and printed each tool, which did work perfectly fine. There’s nothing wrong on the server side, it must be an error sending it between. I have looked into unpacking the table but still, returns nil.

I’m pretty sure since you’re inserting the tools which are still parented to ServerStorage the client can’t see the tools.

2 Likes

Your script returns nil because you need to clone the object and set the parent to a service that is accessible to both sides, such as ReplicatedStorage. Or you can simply change the parent manually or with a script.

If you have the ability to clone an object and set the parent to workspace or replicatedStorage, I highly recommend doing so.

3 Likes

I appreciate your input, however I couldn’t facilitate that as this is on a scale of ~100 tools and that would be performance heavy. However I’ve decided to send the table of strings (the tool’s names) to the client which works, as the client actually doesn’t need the Tool Object.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.