Shared table not able to be accessed serverside?

I currently have this table in a shared file:



SH_EXAMPLE_TABLE = {};
function inserttables()
     table.insert(SH_EXAMPLE_TABLE, "example")
end
inserttables()


Everything works fine on the client’s side, grabbing the table and all, but when I attempt to get the table serverside, it doesn’t exist.

How would I fix this?

No way that’s true unless the file isn’t really shared.

Edit: do you run the file from init.lua?

The file is located in autorun, and the file that is trying to get the data from the table is located in autorun/server

I run that function in the autorun file

you should make a own lua folder for your addon, and then include those in your autorun in the wanted realm, like the autorunfile being youraddonname_includer.lua and the include files being in /addons/youraddonname/lua/youraddonname/REALM

*/REALM/ is not needed.

I had it like that before I put it into autorun.

I moved it to autorun to test to see if that was why my table wasn’t being able to be fetched serverside.

[editline]17th April 2016[/editline]

Alright, I put my addon back into that format, but it still isn’t allowing me to fetch the table serverside.

How are you trying to get it server side?

I just do



for k, v in pairs(SH_EXAMPLE_TABLE) do
     print(v)
end


If that is what you mean.

When are you running it?

In a net message that a client sends to the server.



net.Receive("test_nm", function()
     for k, v in pairs(SH_EXAMPLE_TABLE) do
         print(v)
     end
end)


Are you sure the net message is working?

Yeah, im sure it works.

I don’t know what you’re doing wrong then, works perfectly fine for me

autorun/kek.lua



KEKKY = {}
table.insert(KEKKY, "yes")


autorun/client/kek_c.lua



concommand.Add("give_the_keks",
  function()
    for _, v in pairs(KEKKY) do
      print("CLIENT", v)
    end

    net.Start "GetTheKeks"
    net.SendToServer()
  end,
  nil,
  "Send them the keks"
)


autorun/server/kek_s.lua



util.AddNetworkString "GetTheKeks"

net.Receive("GetTheKeks", function(_, ply)
  print(ply, "gave you the keks")

  for _, v in pairs(KEKKY) do
    print("SERVER", v)
  end
end)


http://puu.sh/olbRx/25fb4e34dc.png