Edit my Money System?

Hello! i finished my money system and im having a tad of a problem with it.
i beleive everything in the actual System is fine, yet i cant get my give-money-on-kill code working!(ex. moeny doesnt rise when you get a kill)
heres the system:

[lua]
local ply = FindMetaTable(“Player”)
local MoneyMod = {}

local function InitialPlayerSpawn(pl)
pl:SetNetworkedInt(“money”, 0)
pl.Money = 0
pl.Salary = {}
end
hook.Add(“PlayerInitialSpawn”, “MoneyMod_PIS”, InitialPlayerSpawn)

local function ResetMoney()
if SERVER then
for k,v in pairs(player.GetAll()) do
v:SendLua(“LocalPlayer():SetNetworkedInt(“money”, “… v.Money …”)”)
end
end
end
//timer.Create(“ResetMoneys”, 0.5, 0, ResetMoney)

function ply:GetMoney()
return self:GetNetworkedInt(“money”)
end

function ply:CanAfford(price)
if SERVER then
return self.Money >= price
else
return self:GetNetworkedInt(“money”) >= price
end
end

if SERVER then
function ply:SetMoney(amt)
self.Money = amt
end

function ply:GiveMoney(amt)
	self.Money = self.Money + amt
end

function ply:TakeMoney(amt)
	self.Money = self.Money - amt
end

function ply:SetSalary(time, amt)
	self.Salary.Time = time
	self.Salary.Amt = amt
	timer.Create(self:Nick() .."'s Salary", self.Salary.Time, 0, function() self.Money = self.Money + self.Salary.Amt end)
end

function ply:HasSalary()
	if timer.IsTimer(self:Nick() .."'s Salary") then
		return true
	else
		return false
	end
end

function ply:ChangeSalary(time, amt)
	self.Salary.Time = time
	self.Salary.Amt = amt
end

function ply:RemoveSalary()
	if timer.IsTimer(self:Nick() .."'s Salary") then
		timer.Destroy(self:Nick() .."'s Salary")
	end
end

function SaveMoney(pl)
	file.Write(gmod.GetGamemode().Name .."/Money/".. string.gsub(pl:SteamID(), ":", "_") ..".txt", pl.Money)
end

function LoadMoney(pl)
	pl.Money = file.Read(gmod.GetGamemode().Name .."/Money/".. string.gsub(pl:SteamID(), ":", "_") ..".txt", pl.Money)
end

end
–Money HUD below
local function Money_Draw( )
local Cash = LocalPlayer():GetNWInt( “Money” )
draw.DrawText("Money: "…Cash, “KK”, 60, 60, Color(0,255,0,255))
end
hook.Add(“HUDPaint”, “MoneyPainting”, Money_Draw)
[/lua]
and here is the small peice of code for the give-money
[lua]
function Plykill( victim, weapon, killer, ply)
if victim:IsValid() and victim:IsPlayer()
then
killer:GiveMoney( 20 )

end
end

hook.Add( “PlayerDeath”, “Plykill”, Plykill )
[/lua]
Please tell me what went WRONG?

I don’t know what went wrong, but Im using this one system i found in a tut somewhere, I havent been able to test it yet:

function KillCounter( victim, killer, weapon ) --Sets up a new function called KillCounter

        killer:SetNWInt("killcounter", killer:GetNWInt("killcounter") + 1)  --Adds 1 everytime an NPC is killed.
end
hook.Add("OnNPCKilled","KillCounter", KillCounter)

money system is now working.
only one problem though, it doesnt save to a database.
how can i get it to save to a database?

ply:SetPData() Saves to sql!
ply:GetPData() Loads from sql!

this is what i did:
Added to Init.Lua
[lua]
function FirstSpawn( ply )
local cash = ply:GetPData(“money”) --Get the saved money amount

if cash == nil then --If it doesn't exist supply the player with the starting money amount
	ply:SetPData("money", STARTINGMONEY) --Save it
	ply:SetMoney( STARTINGMONEY ) --Set it to the networked ints that can be called from the client too
else
ply:SetMoney( cash ) --If not, set the networked ints to what we last saved
end

end
hook.Add( “PlayerInitialSpawn”, “playerInitialSpawn”, FirstSpawn )

function fPlayerDisconnect( ply )
print(“Player Disconnect: Money saved to SQLLite and TXT”)
ply:SaveMoney()
ply:SaveMoneyTXT()
end
hook.Add( “PlayerDisconnected”, “playerdisconnected”, fPlayerDisconnect )
[/lua]

Replaced SaveMoney and LoadMoney with:
[lua]
function ply:SaveMoney()
local cash = self:GetMoney()
self:SetPData(“money”, cash)
end

function ply:SaveMoneyTXT()
file.Write(gmod.GetGamemode().Name …"/Money/"… string.gsub(self:SteamID(), “:”, “_”) …".txt", self:GetMoneyString())
end
end
[/lua]
AbsoLUTELY no change whatsoever!

[editline]02:36AM[/editline]

Shameles bump.

[editline]02:36AM[/editline]

shameless bump. again

You need to call SaveMoney And SaveMoneyText
[lua]
– if that doesn’t work for k,v in pairs(player.GetAll()) do v:SaveMoney() end
timer.Create(“Save”, 1,0, function(ply)
ply:SaveMoney()
end,ply)
[/lua]

When you set the money you might wanna save it too.

Use the for he commented inside the timer

Cubar’s method will not work, try this:

[lua]
local time = 30 – this is in seconds
timer.Create(“money_SaveAllPlayers”, time, 0, function()
for _, ply in pairs(player.GetAll()) do
ply:SaveMoney()
end
end)
[/lua]

That is his method if you read his comment

That still would not of worked if you read the code.

Well i guess i cant exactly say its 100% right but a lua coder could of still used it as an explanation.

No he couldn’t of, he was passing a nil argument through. And if he were to do it like that he would have to destory all the timers on a player disconnect and give them all unique name’s.

I knew it wouldn’t work but why is this in the wiki,
[lua]
function Ignited( ply )
ply:Ignite(3,0)
end
timer.Create( “Atimer”, 5, 1, Ignited, ply )
[/lua]

It’s just an example on the wiki to show that an argument can be passed through a timer.

alright thanks a ton.
one more thing,
im having a bit of trouble with the money-saveing.
for instance, if a player normally disconnects, the money is saved.
if they accidentaly crash then it gets set back to the last save. same goes with a map change. my gamemode does alot of map changes, so this wont be good. i tried adding a save function to the end of the plykill function so the money is saved Every time you get more, but all this has done is TOTALY screwed with ti to a point that players dont GET any money for kills.
i tried just adding the ply:SaveMoney() and the ply:SaveMoneyTXT() but nothing happened =\

[lua]
function Plykill( victim, weapon, killer, ply)
if victim:IsValid() and victim:IsPlayer()
then
killer:SetNWInt(“Money”, killer:GetNWInt(“Money”) + 20)
killer:SaveMoney()–doesnt work
killer:SaveMoneyTXT()–doesnt work
– i have also used ply:SaveMoney in both scenarios, no luck.
end
end
[/lua]
D:

Change
[lua]function ply:SaveMoneyTXT()
file.Write(gmod.GetGamemode().Name …"/Money/"… string.gsub(self:SteamID(), “:”, “") …".txt", self:GetMoneyString())
end [/lua]
to
[lua]function ply:SaveMoneyTXT()
print(“Saved " …gmod.GetGamemode().Name …”/Money/"… string.gsub(self:SteamID(), “:”, "
”) …".txt" ) – if this works then there should be no problem with the saving
file.Write(gmod.GetGamemode().Name …"/Money/"… string.gsub(self:SteamID(), “:”, “_”) …".txt", self:GetNWInt(“money”,0))
end [/lua]