So I (with help of some people) wrote this save system, but it doesn't quite work.
The problem is, the data is nulled right before it's loaded and therefore, even though the save file has the money as 100000000, it's still loaded as 2000.
If someone could please help me out with this, I'd greatly appreciate.
Code
More 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
function string.split(t, b) 	local cmd = {} 	local match = "[^%s]+" 	if b then 		match = "%w+" 	end 	if type(b) == "string" then match = "[^"..b.."]+" end 	if not t then return invalid() end 	for word in string.gmatch(t, match) do 		table.insert(cmd, tonumber(word)) 	end 	return cmd end function table.msg(t) 	local str="" 	for _,v in ipairs(t) do 		if (str=="") then 			str=str..v 		else 			str=str..","..v 		end 	end 	return str end function dataset(id,dn,d) 	local dd=tonumber(d) 	if (dn==1) then 		credits[id]=dd 	elseif (dn==2) then 		shield[id]=dd 	elseif (dn==3) then 		armor[id]=dd 	elseif (dn==4) then 		energy[id]=dd 	elseif (dn==5) then 		pos[id][1]=dd 	elseif (dn==6) then 		pos[id][2]=dd 	elseif (dn==7) then 		inParty[id][2]=dd 	elseif (dn==8) then 		shipt[id]=dd 	elseif (dn==9) then 		cwslots[id]=string.split(d,",") 	elseif (dn==10) then 		invslot[id]=string.split(d,",") 	end end function datanull(id) 	credits[id]=2000 	armor[id]=100 	shield[id]=100 	energy[id]=500 	pos[id]=spawnPos 	inParty[id]={false,0} 	shipt[id]=1 	cwslots[id]={1,0,0,0,0,0,0,0,0} 	invslot[id]={1,0,0} 	firsttime[id]=true end function datasave(id) 	if (player(id,"usgn")>0) then 		local usgn=player(id,"usgn") 		os.execute('touch "/home/engi/public_rpg/sys/lua/space_rpg/savedata/'..usgn..'.sav"') 		os.execute('chmod 666 "/home/engi/public_rpg/sys/lua/space_rpg/savedata/'..usgn..'.sav"') 		local m = assert(io.open('sys/lua/space_rpg/savedata/'..usgn..'.sav','w')) 		m:write(credits[id].."\n"..shield[id].."\n"..armor[id].."\n"..energy[id].."\n"..pos[id][1].."\n"..pos[id][2].."\n"..inParty[id][2].."\n"..shipt[id].."\n"..table.msg(cwslots[id]).."\n"..table.msg(invslot[id])) 		m:close() 		msg2(id,"Data save completed successfully!") 	else 		msg2(id,"Data save failed - not logged into USGN!") 	end end function dataread(id) 	if (player(id,"usgn")>0) then 		local usgn=player(id,"usgn") 		local m = assert(io.open('sys/lua/space_rpg/savedata/'..usgn..'.sav','r')) 			linen = 1 			lines = {} 			for line in m:lines() do 				msg("Line #"..linen..": "..line) 				dataset(id,linen,line) 				linen=linen+1 			end			 			m:close() 			msg2(id,"Data load completed successfully!") 	else 		msg2(id,"Data load failed - not logged into USGN!") 	end end addhook("join","player_load") function player_load(id) 	dataread(id) end addhook("leave","player_save") function player_save(id) 	datasave(id) 	datanull(id) end