Does the Server serializes values sent over to the client?

Hi there!

I would like to know if the Client to Server Model serializes values/data being sent between the two entities.

The issue is, I sometimes have unpredicted & unreliable results, do dictionaries get serialized? do metatables get serialized? do tables get serialized? etc.

I’ve tried to print out each value that was returned from a RemoteFunction from the server, some did print out to the Output, however some did not. I’m looking for what the server serializes and how it serializes values before returning them to a client VIA a RemoteFunction.

If you are confused by what I mean, here’s a example for you:

ServerScript inside of ServerScriptService

local remoteFunction = game.ReplicatedStorage.RemoteFunction

local myValue1 = "A string"
local myValue2 = 69
local myValue3 = true
local myValue4 = Enum.KeyCode.E

remoteFunction.OnServerInvoke = function()
      return { -- heres an example of a dictionary.
          Index1 = "A string"
          Index2 = function() end
      }, myValue1, myValue2, myValue3, myValue4
      -- % return a dictionary as well as a few example values.

LocalScript inside of StarterGui

local remoteFunction = game.ReplicatedStorage.RemoteFunction
local dictionary, myValue1, myValue2, myValue3, myValue4 = remoteFunction:InvokeServer()
print(dictionary, myValue1, myValue2, myValue3, myvalue4)
-- /\ /\ I would like to know what that all prints.

Please reply for any clarification, questions, topics, discussion, do not be shy lol.

You never showed a example of what’s wrong. Your code doesn’t explain.

You question is does metatables replicate with the table to the client?.
Here what i got:

local uis = game:GetService("UserInputService")
	if i.KeyCode == Enum.KeyCode.E then
		local meta = game.ReplicatedStorage.RemoteFunction:InvokeServer()
		meta = meta+1 -- errors
local x = {
	__add = function() print("xd") end
game.ReplicatedStorage.RemoteFunction.OnServerInvoke = function()
	local t = {}
	t+=50 -- works
	return t

Metatable cannot be serialized and are not sent over RemoteEvents or RemoteFunctions with exception to the standed metatables which roblox provides such as Vector3 or CFrame.

Intuitively this should make sense because allowing the serialization of arbitrary lua bytecode to be interpreted to any client or server its sent to is obviously not safe.

1 Like

Hm, thanks for the reply.
I’m guessing that all values don’t get serialized except Enums do, I’ll find a workaround that.

If that’s the case, why do Enums get serialized as well?
I noticed that they are converted to string values when the client receives them.

Take for example:

remoteFunction.OnInvoke = function() return Enum.KeyCode.E end



-- Output:
-- <token: xxxxx>

It’s supposed to print: Enum.KeyCode.E however, the server serializes it into a string
Weird isn’t it?

Everything gets serialized (probably to json but i’m not sure exactly) to be sent. You can change the way it serializes by coercing the Enum to string:

  return tostring(Enum.KeyCode.E) 
1 Like

Interesting topic to know, I was going to do the exact same thing but you made it more simpler lol, thanks alot!