Client Table Issue

Im currently trying to sync a table between the server and the client.

Here is my current code:

Serverside:



local _R = debug.getregistry().Player
util.AddNetworkString("sync_table")
function _R:SyncTable()
	if (!self.TableSync) then
		self.TableSync = {};
	end
	
	net.Start("sync_table")
		net.WriteString(util.TableToJSON(self.TableSync));
	net.Send(self)
	ServerLog("SENT THE NETMESSAGE")
end
hook.Add("PlayerInitialSpawn", "TestTableSync", function(ply)
	ply:SyncTable();
end)


Client:



net.Receive("sync_table", function()
	LocalPlayer().TableSync = util.JSONToTable(net.ReadString());
end)


In console it prints:

SENT THE NETMESSAGE

But when I attempt to print the table clientside it shows up nil.

Any reason for this?

try adding a timer where you’re doing ply:SyncTable();

I tried that already, for 5 seconds, but it still didnt sync it.

I can try again, though.

[editline]28th April 2016[/editline]

yeah, I just tried it. It still didnt work:



	timer.Simple(10, function()
		ply:SyncTable()
	end)


Alright, I just put a print statement in the net.Receive, and it didnt print.

I dont know why the client isnt getting the net message.

Make sure the file is being ran clientside. Move the print outside the receiver.

I fixed the issue. Thanks guys!

I have one more question, how would I set the color of a panel without having to repaint everything?

I was trying to do something similar, I was unhappy with the timer solution and eventually found out about this hook:


GM:PostGamemodeLoaded() 

its a server/client hook. The client would be fully in the server at the time this hook is called (unlike playerinitialspawn).