DataTables getting cleared..

I’m deriving a gamemode from sandbox.

These are my spawn functions(Player spawns fine as expected):



function GM:PlayerInitialSpawn( ply )
    player_manager.SetPlayerClass( ply , "player_buildtools" )
end

function GM:PlayerSpawn( ply )
    player_manager.OnPlayerSpawn( ply )
    player_manager.RunClass( ply, "Spawn" )
    player_manager.RunClass( ply, "SetModel" )
    player_manager.RunClass( ply, "Loadout" )

end


This is the code im using to setup data tables:



local PLAYER = FindMetaTable("Player")

function PLAYER:SetupDataTables()
    self:NetworkVar( "Int", 0, "Money")
    self:SetMoney(234)
end

hook.Add( "PlayerInitialSpawn" , "PlayerInitialSpawnSyncData" , function( ply )
    ply:InstallDataTable()
    ply:SetupDataTables()
    print(ply:GetMoney())                                                                                --This prints "234"
    ply:SetMoney(4000)                                                                                 --No errors
    print(ply:GetMoney())                                                                               --This prints "4000"
end)


After the previous, I have this code somewhere(serverside):



hook.Add("PlayerSay","Test1",function( ply, text, team )
    if(string.StartWith(text,"!ServerGetMoney")) then
        print(ply:GetMoney())                                                              --This prints nil? - when I type in chat "!ServerGetMoney"
    end
end)


I have no idea why my tables are being reset, they clearly work during the initial spawn hook. I’m even using player_manager without referencing the baseclass, so the setupdatatables shouldnt be called from the playerclass.
I’ve tried getting a table of all the hooks, but I dont see anything obvious that would override this…I can post the table later if anyone is interested.

I’ve tried finding what exactly is resetting my datatables with no success…Any ideas would be greatly appreciated!

bump, still stuck on this issue =/

Do you call SetupDataTables on server-side?

Thanks for the reply. Yes all the code above is ran serverside.

[editline]30th April 2016[/editline]

Well it works if I add the tables to the player_class, “self.Player:Networkvar…”

And then on playerinitialspawn


player_manager.RunClass(ply,"SetupDataTables")

I guess the problem is running it clientside and serverside near the same time? I’ve gotten it to also work by having the server hook PlayerSay and client OnPlayerChat run the setupdatatables at the same time(setupdatatables in shared.lua), but what hooks would be better that would be called on both? Is there some way to find out if the client has loaded from the server without networking stuff?

Client wise I would use the


GM:PostGamemodeLoaded() 

, on the server I would use PlayerInitialSpawn but the client isnt in game during that hook, PlayerSpawn works but I dont want it called every spawn.

Anyone know a good way to hook this without sending/receiving network library data?

[editline]30th April 2016[/editline]

I really dont understand the dynamics of this, how come player_manager can get it to work when called from the PlayerInitialSpawn hook? I suppose it has some smarts to check for the right time to execute the setup on its own?

I just need a hook thats called once on the server and client when the client is fully loaded into the server. :wavey: