• Trying to call ply:Health() in OnPlayerDisconnected hook
    5 replies, posted
So I'm calling the hook "OnPlayerDisconnected" server side and I know it is indeed responding because it will react to print() statements. My problem is that when I call ply:Health(), it returns nothing. I am trying to have their health put into a database so that when they return, their health is saved. I can call their name and steamid in this hook but their health just isn't kicking back. I've accomplished this in the past but I forgot how. I'm pretty damn sure this is how I did it before but apparently not. print(ply:Health()) doesn't do anything. I speculated that perhaps once the player is considered gone that the health is dropped, but the name would be too. Sort of confused. Any help would be greatly appreciated.
Post your code.
[CODE] hook.Add( "PlayerDisconnected", "PlayerDisconnected", function( ply ) print(ply:Health) -- I put this here to see if maybe my database functions were taking too long and maybe by the end of the function the player was considered gone and I could no longer use the player entity or something, but it wont work here either. MsgC( Color( 0, 0, 255 ), "Player " .. ply:Name() .. " has disconnected from the server. (SID " .. ply:SteamID() .. ")\n" ) -- This statement does work. local tab = database_retrievechar( ply, ply.chardata.id ) -- I used a PrintTable() earlier to make sure that "tab" was being loaded with the correct table, and it is. tab.health = ply:Health() -- PROBLEM IS RIGHT HERE print(ply:Health) -- Just here to see if ply:Health() was working at all and it isn't. database_savechar( ply, tab ) -- This is updating the database, but the "health" key isn't changing. end ) [/CODE] database_retrievechar() and database_savechar() are both functional. I have used ply:Health() in the clientside code for my HUD but not anywhere serverside other than this. It works clientside.
ply:Health has no args, make sure it is ply:Health()
-late-
Roger. That was messing it up somehow. It was working actually and I had another function messed up. Missing the args on the ply:Health() for the print statement led me to believe the function was messed up. Thanks for the help. I probably would have never found it. Hooah.
Sorry, you need to Log In to post a reply to this thread.