Tables not replicating from server to client?

Hello developers!

Today I stumbled upon an issue while making my radio system. The client fires an event where the server will retrieve the message and make a message data table then send it down to the client. When it gets sent down to the client, it keeps saying it’s nil. Is there a replication issue?

Here is the code I used:

--server
function constructMessageData(author, message, systemMessage, team)
	systemMessage = systemMessage or false
	if author and message and team then
		local messageData = {}
		messageData.Author = author
		messageData.Message = message
		messageData.SystemMessage = systemMessage
		messageData.Team = team
		return messageData
	end
end


function onRadioMessageEvent(player, channel, msg)
	channel = channel or "Global"
	if msg then
		local filteredText = TextService:FilterStringAsync(msg, player.UserId)
		local isSystem = false
		if not filteredText then isSystem = true filteredText = string.format("A message was sent by %s, but failed to filter.", player.Name) end
		local messageData = constructMessageData(player.Name, filteredText, isSystem, player.Team.Name)
		Remotes.MessageEvent:FireAllClients("Global", {messageData})
	end
end

After the table is sent down to the client, it says it’s nil. Any fixes here? Would be much appreciated.

Here’s a screenshot from the output:

Edit: Just resolved this issue myself, see the posts below.

Where’s the client code? We need it to be able to assess the issue.

You are losing data over remotes due to limitations. Mixed indices (or dictionaries) cannot be sent over remotes without losing data.

1 Like

Ah this makes sense, thank you for addressing this to me.

This is not accurate. Dictionaries absolutely do serialize properly when passed through a remote object. A table won’t serialize properly when:

  1. It contains mixed indices (this is not the same thing as a string-keyed table)
    OR
  2. It’s an integer-keyed table which contains “holes,” i.e. the values of some keys are equal to nil

@az_iee, please provide your client side logic so we can properly help you with this issue

4 Likes

Nevermind, I just solved it myself because I put the “messageData” table inside of another table which caused it to say nil. So you are right, I can do that. Thanks for trying to resolve my issue everyone.