Why I cant read shared table data from client?



TBL = {}
TBL.Table = {}
TBL.Func = {}

function TBL.Func.Fuunc(ply)
if ply:IsCP() then return 50 end -- just for example
end

if SERVER then
local table = {  lol = 1, lol2 = two }
table.insert( TBL.Table, table )
end

if CLIENT then
timer.Simple(10, function()
TBL.Func.Fuunc(LocalPlayer()) -- returns 50 if ply really is CP
print( #TBL.Table ) -- returns 0
end)
end


The code above doesn’t work correctly. How I can parse TBL.Table from client if this table contains data from server?

This is a common misconception about what shared means.

Shared is a file that the clients execute individually, and that the server executes as well.

Code not in a ‘if CLIENT’ or ‘if SERVER’ statement gets ran by every personal computer connected to the server as well as the server itself.

Code in ‘if CLIENT’ gets ran by only the player computers. Code in ‘if SERVER’ gets ran by only the server hosting the players.

The table isn’t networked so that all values changed on the server change on the client. Instead, each individual machine (client and server) each processed the code to be an empty table, but only the server filled that table with values. Being a file executed individually by both client and server does not mean it networks values. It just means you don’t have to write the same code twice in both cl_init.lua and init.lua, because both of those files ‘include’ the shared file, meaning it just runs the code in shared.

You could name the shared file “dicks.lua” and have cl_init.lua and init.lua include that instead and achieve the same purpose. There is nothing special about the filename ‘shared.lua’, only cl_init and init.

To network values, you need the net library.