Better ways to send a specific table entry to the client?

I currently have a table with different numbers inside (server-script - ModuleScript).
It kinda looks like this:

local Table = {
	[1] = {
		Test = 12345
	}
}

Just to clear up: Yes, I am currently using a RemoteEvent for this.

The issue starts when I would like to transfer that data over to the client (Table[1]).
Since the client is not able to see this it’ll return nil, and I don’t feel like replacing a script with StringValues / other objects just to send its content to the client.

What would be the best way to send over this information (without placing the script anywhere but ServerScriptService, as I don’t want exploiters to read the code)?

I have a few solutions in my mind, however I wanna see if anyone else has a better solution.
Perhaps a hacky solution to somehow send the value within the script to the client (?)

1 Like

There is no other secure way to send data rather than using remote events. You can pass a table with the signal. However, if the module script contains a table that doesn’t change (values that are constant), you could separate module with the data and make the module accessible to both parties by putting it in ReplicatedStorage.

1 Like

The client should be able to see the table fine, it shouldn’t be nil


What does the actual script look like?

1 Like

You cannot pass the table as it will be nil on the client.

They can see the code if it’s being required by a localscript, as it will then act as a localscript, and exploiters can access and read that.

My mistake, I thought you were talking about a server script

I am, however I don’t want to move the modulescript ouf of my Modules folder in SSS, as that is where I keep all my modulescripts.

I need a simple way to transfer data within a table to the client via the server.

I know this may sound like a stupid response, but did you try putting that table entry into a variable and sending it to the client instead of a direct reference to the table?

If you make it a variable, you still have a reference to the table which makes no difference.

Of course tables are passed as well. However, you can’t fire remotes from module scripts individually, as you first have to require them in order for them to start executing.

EDIT Yes, and I told you that you can either share a module script in case table values are constant. If that is not the case, you can freely transfer the table using remote events. Pass the whole table or part of the table correctly and the client will accept it.

Take a look at the following example:

Server script (can be required module script):

local Table = {"a", "b", "c"}

game:GetService("Players").PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		game:GetService("ReplicatedStorage").Event:FireClient(player, Table)
	end)
end)

Local script:

game:GetService("ReplicatedStorage").Event.OnClientEvent:Connect(function(Table)
	print(Table)
end)
  • remote event in ReplicatedStorage named Event.

EDIT (2) @Syclya

Just like @HugeCoolboy2007 said as well, any table can be sent (unless it’s extremely large in size). I understand your issue. And both of us would like to tell you that you can require a module, and send a table (or part of that table) with remote event. You probably have your table stored this way:

local module = {}

module.YourTable = {}

return module

-- Server script:

local module = require(script.ModuleScript)
local yourTable = module.YourTable

You have at least two ways to send the table with module script.

  1. From server script:
local module = require(script.ModuleScript)
local yourTable = module.YourTable -- send this table
  1. by calling a method
function module.SendTable()
	-- send from here
end

-- Server script
local module = require(script.ModuleScript)
module.SendTable() -- send the table

Read before commenting. The module is obviously required, that is not my issue.

The issue is that the value being sent is nil on the client side.

The client will not accept it because it will return nil as the client cannot see the table.

EDIT

You don’t get what I’m talking about.
The table is stored inside the modulescript, not where the event is fired as that is a completely different script, but the modulescript is required.

What does the client script look like when it’s receiving the table and what does the module script look like when it sends the table?

In order for the table to be nil, there has to be either values stored in the table that don’t replicate or the way it’s being sent/received is incorrect

Sadly that’s the issue, a hacky solution would be to create a object to store the number in, then send the object’s value to the client, might as well do that.

And no, nothing within SSS is replicated to the client, ever.
Neither ServerStorage as those services are server-sided only.

After some further investigation, I was wrong as I found it weird that it would return nil when it’s a number.

What I accidentally did was updating the wrong part of the code, which didn’t even send over the table, hence the nil as there was nothing being sent.

No further comments needed, thanks anyways! (should’ve investigated beforehand, silly mistake.)

1 Like