Search code examples
luaserverclientlua-tablegarrys-mod

Shared Table not printing on Client


Basically I have a SHARED lua file where I define the table. I did this because I thought if we define the Table in a shared file we can use it client and server side.

SHARED.lua:

TableA = {}

Then I edit it on a SERVER lua file.

SERVER.lua:

function UpdateTable()
    // Clean Table first
    for k in pairs(TableA) do
        TableA[k] = nil
    end
    ... not worth showing the rest ...
    // Insert New Values
    for i=1, 10 do
        table.insert(TableA, result[i])
    end
    // Debug Print
    print(table.ToString(TableA)) // It Prints every value correctly
end

Now when I try to print it client side, it says the Table exists but it's empty.

CLIENT.lua:

print(table.ToString(TableA))// Prints "{}" and it shouldn't be empty

Note: UpdateTable() runs every 5min


Solution

  • Apparently when we define a table shared, doesn't mean the values will be shared through the server and client. It only means that the code will run on both server/client. You have to network them for them to "share" the values on the table.