ID:2342095
 
(See the best response by IainPeregrine.)

Hud
NewCharacter
maptext="<font style=\"font-family:monospace;\" color=white size=4>New Character</font>"
maptext_width=500
maptext_height=500
screen_loc="CENTER-12,CENTER-7"
icon='characterclick.dmi'
maptext_y=32

Click()
..()
var/mob/user=usr
if(user&&user.client&&!user.slot_selected)
alert(user,"Select a slot")
return

if(user&&user.client&&user.slot_selected)
if(fexists("Players/[user.ckey]/[user.slot_selected].sav"))
alert(user,"Delete this slot first!")
return
user.FadeScreen()
var/mob/newmob = new/mob/human/player(locate_tag("maptag_creation_appearance"))
user.new_character=1
newmob.new_character=1
newmob.slot_selected=user.slot_selected
user.client.RemoveHud()
newmob.invisibility=100
newmob.initialized=0
user.client.mob=newmob
user.client.eye=newmob
newmob.Refresh_example()


Problem description:

I created a Hud obj for logging players in and creating new players. For some reason the user AND the client keep disappearing.
I'm getting a myriad of runtime errors from multiple lines for null.RemoveHud() and null.client.
Now some players aren't able to log into their saves.

How can I prevent the user or the client from going away?
Will I have to create a new save system?

Best response
In the third to last line you assign the client a new mob. This disconnects the client from the old mob, meaning that user.client is now null. The good news is that newmob.client isn't null, so you can use that.
In response to IainPeregrine
Sorry, I forgot to mention this happens with my character Load as well where it says user.client.RemoveHud() and user.client.LoadMob() as well. Where is the client? What is happening to it?
Hud
LoadCharacter
maptext="<font style=\"font-family:monospace;\" color=white size=4>Load Character</font>"
maptext_width=500
maptext_height=500
screen_loc="CENTER-5,CENTER-7"
icon='characterclick.dmi'
maptext_y=32


Click()
..()
var/mob/user=usr
if(user&&user.client&&!user.slot_selected)
alert(user,"Select a slot")
return

if(user&&user.client&&user.slot_selected)

if(!fexists("Players/[user.ckey]/[user.slot_selected].sav"))
alert(user,"No save file found in [user.slot_selected]")
return

var/savefile/F = new("Players/[user.ckey]/[user.slot_selected].sav")
var/list/S = new/list()
F["S"] >> S
user.client.RemoveHud()
user.client.LoadMob(S,user.slot_selected)
if(S)del S
It doesn't look like the problem is in this section of code. It's easier to debug when we can see the exact error, like "cannot access null.mob, file: whatever.dm, line: 52"
If you can post those errors, and then post the code that contains those lines (and tell us which line is line 52, for instance) then we have a much better chance of figuring out what's going on.
runtime error: Cannot read null.RemoveHud()
login.dm,445

runtime error: Cannot read null.client
login.dm,446


user.client.RemoveHud()// line 445
user.client.LoadMob(S,user.slot_selected)//line 446
In response to Ghost Gaming
I don't believe in Click() events that "usr" is the Mob. also, it's very confusing calling the mob "user". Try changing it to

var/mob/player = client.mob

( if that doesn't compile I'm misremembering, add usr. to client.mob, so it says usr.client.mob (
It's been a while since I worked with savefiles so I can't get into the nitty gritty, but here's what's happening:

var/savefile/F = new("Players/[user.ckey]/[user.slot_selected].sav")
var/list/S = new/list()
F["S"] >> S


F["S"] has a mob saved in it. Either because you were saving a mob there, or because a mob got accidentally saved with another object (more on this in a moment). When that mob was saved, its key variable was saved, too. So when that mob is recreated, it gets recreated with its key already set. This causes any player with that key to disconnect from their current mob and connect to the new mob. This causes user.client to become null.

Mobs can get accidentally saved if you're saving another object that's holding a reference to the mob. Take a look at this for example:

sword
var/mob/owner
verb/equip(mob/equipper)
owner = equipper


When that sword is put into a savefile the owner mob will also be put into the savefile. To prevent this, make the owner variable a temp variable:
var/tmp/mob/owner

Or, you can use the owner's key instead of their mob:
var/tmp/ownerKey = equipper.key