Syncing metatables across client and server...

so i would expect metatables to be updated one one end also updated on the other… nope.
if i set a player’s squad (networked string) on server, client still says it’s nil.
do i have to use networking / usermessages or am i missing something? there arent really any good metatable tutorails

Uhhh, I think you’re misusing the word ‘metatable’. Are you saying you’re doing something like ply.Squad = “Cops” on the server but it’s not setting it on the client as well? If so then that is the intended result. To network a variable between server and client use either Datatable Vars or NWVars.

No, this is what I’m doing:

  1. include and AddCSLuaFile sh_meta.lua

[lua]local plyMeta = FindMetaTable(“Player”);

function plyMeta:SetClass(class)
self:SetNetworkedInt(“Class”, class);

function plyMeta:Class()
return self:GetNetworkedInt(“Class”);

function plyMeta:SetSquad(squad)
self:SetNetworkedString(“Squad”, squad);

function plyMeta:Squad()
return self:GetNetworkedString(“Squad”);

Setting and reading squads and classes works 100% on the server, but on the client, calling LocalPlayer:Squad() results in a nil value.

Hrm, I think your code should work but the SetNetworkedString function is depricated now so I’d just get rid of it. Try using

Entity:SetNWString instead?

[editline]1st May 2015[/editline]

Also make sure you’re not calling SetSquad on the client as this will cause the client to get desynced from the server. Unless you’re certain that they are the same value.

entity? as in i need to create an entity for this or as in ply:SetNWString? do i have to abandon metatables?

EDIT: SetNWString works perfectly!