Instances as keys not replicating properly via remotes

I have a table of enemies with the enemy’s character as the key, and the enemy table as the value, and I’m requesting this table on join through a remote function

Server

		enemyRequestRF.OnServerInvoke = function(rbxPlayer)
			local configs = {}
			for character, enemy in pairs(EntityList:GetEnemies()) do
				print("SERVER", character, enemy.Config)
				configs[character] = enemy.Config
			end
			return configs
		end

Client

		local configs = enemyRequestRF:InvokeServer()
		for character, enemyConfig in pairs(configs) do
			print("Client", character, enemyConfig)
		end

image

If I pass the character itself as the value it replicates properly, but when the key is a instance it will replicate as a string rather than as a instance

I already know a workaround for this, but I don’t know why this is happening

Is this a bug, or is it intended behavior?

bump

i had the same issue, and i also found a work around which was to separate the keys and values into two arrays, sending the two arrays to the client, and then reassembly a copy of the original table using the two arrays

but im really curious why this happens

This behavior is intended. You can see this at the Argument Limitations section of Remote Events and Callbacks on the documentations.

3 Likes