Gamemode Help, PLEASE DONT IGNORE!!!!!!!!

Hello all, I am in the process of making a gmod gamemode where you get money for npc kills!!! :smiley: I got it to work BUUUUUT it gives you money whenever ANYONE kills an npc, is there any way to make it so that it will ONLY give you money if YOU kill the npc???

CODE:

init.lua


AddCSLuaFile( "shared.lua" )
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "sh_player.lua" )
include( "sh_player.lua" )

include( "shared.lua" )

MONEY_STARTAMOUNT = 1000 --Can be changed to your starting amount
function GM:PlayerSpawn( ply )
	ply:StripWeapons()
	ply:Give("weapon_crowbar")
end
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", MONEY_STARTAMOUNT) --Save it
		ply:SetMoney( MONEY_STARTAMOUNT ) --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 PrintCash( pl )
	pl:ChatPrint("Your cash is: " .. pl:GetMoney())
end
 
function fPlayerDisconnect( ply )
	print("Player Disconnect: Money saved to SQLLite and TXT")
	ply:SaveMoney()
	ply:SaveMoneyTXT()
end
 
concommand.Add("cash_get",PrintCash)
 
	
function GM:PlayerInitialSpawn( ply )
	ply:SetTeam( 1 )
end

function NPCKill( ply )
	ply:AddMoney( 10 )
	ply:ChatPrint("You killed an NPC, and gained 10 dollars!")
end

function GM:ShowHelp( ply ) -- This hook is called everytime F1 is pressed.
    umsg.Start( "MyMenu", ply ) -- Sending a message to the client.
    umsg.End()
end --Ends function

function MyMenu( ply ) --Start the function
    umsg.Start( "MyMenu", ply ) --Send the contents of "MyMenu" to the client
    umsg.End()
end --End the function
hook.Add("ShowHelp", "MyHook", MyMenu) --Add the hook "ShowHelp" so it opens with F1

function GiveShtgAmmo( ply )
	cash = ply:GetMoney()
	if cash >= 50 then
		ply:TakeMoney( 50 )
		ply:GiveAmmo(80, "Buckshot")
		ply:ChatPrint("Gave you 80 shotgun ammo.")
	else
	ply:ChatPrint("You don't have enough money for shotgun ammo.")
	end
end

function GivePistol( ply )
	cash = ply:GetMoney()
	if cash >= 80 then
		ply:TakeMoney( 80 )
		ply:Give("weapon_pistol")
		ply:GiveAmmo(30, "pistol")
	else
	ply:ChatPrint("You don't have enough money for a pistol.")
	end
end

function GivePistAmmo( ply )
	cash = ply:GetMoney()
	if cash >= 50 then
		ply:TakeMoney( 50 )
		ply:GiveAmmo(100, "pistol")
		ply:ChatPrint("Gave you 100 spistol ammo.")
	else
	ply:ChatPrint("You don't have enough money for pistol ammo.")
	end
end

function GiveM4( ply )
	cash = ply:GetMoney()
	if cash >= 300 then
		ply:TakeMoney( 300 )
		ply:Give("weapon_m4")
		ply:GiveAmmo(75, "smg1")
	else
	ply:ChatPrint("You don't have enough money for an M4.")
	end
end

function BuyRifleAmmo( ply )
	cash = ply:GetMoney()
	if cash >= 100 then
		ply:TakeMoney( 100 )
		ply:GiveAmmo(100, "smg1")
	else
	ply:ChatPrint("You don't have enough money for rifle ammo.")
	end
end

function GiveShotgun( ply )
	cash = ply:GetMoney()
	if cash >= 150 then
		ply:TakeMoney( 150 )
		ply:Give("weapon_shotgun")
		ply:GiveAmmo(20, "Buckshot")
	else
	ply:ChatPrint("You don't have enough money for a shotgun.")
	end
end

concommand.Add("NPCKill",NPCKill)
concommand.Add("buy_shotgun",GiveShotgun)
concommand.Add("buy_shtg_ammo",GiveShtgAmmo)
concommand.Add("buy_pist_ammo",GivePistAmmo)
concommand.Add("buy_pistol",GivePistol)
concommand.Add("buy_m4",GiveM4)
function GM:OnNPCKilled( victim, killer, weapon )
   RunConsoleCommand("NPCKill")
end

shared.lua


GM.Name = "First Gamemode"
GM.Author = "=YRS= Cwkimzey"
GM.Email = "cwkimzey@gmail.com"
GM.Website = "www.www.com.com"

DeriveGamemode( "sandbox" )

team.SetUp(1, "Red", Color( 255, 0, 0, 255 ) )
team.SetUp(2, "Blue", Color( 0, 0, 255, 255 ) )
team.SetUp(3, "Spectators", Color( 25, 25, 25, 25 ) )

cl_init.lua


include( "shared.lua" )
include( "sh_player.lua" )
local function MyMenu()
    local Menu = vgui.Create("DFrame")
    Menu:SetPos(10, 10)
    Menu:SetSize(800, 350)
    Menu:SetText("My Menu")
    Menu:SetDraggable(false)
    Menu:ShowCloseButton(true)
    Menu:MakePopup()
	
	local Ammo = vgui.Create("DCollapsibleCategory", Menu)
	Ammo:SetPos(20, 40)
	Ammo:SetLabel("Weapons")
	Ammo:SetSize(350, 20)
	Ammo:SetExpanded(0)
	
	local Col = vgui.Create("DCollapsibleCategory", Menu)
	Col:SetPos(380, 40)
	Col:SetLabel("Ammo")
	Col:SetSize(350, 20)
	Col:SetExpanded(0)
	
	local WList = vgui.Create( "DPanelList" )
	WList:SetAutoSize(true)
	WList:SetSpacing(5)
	WList:EnableVerticalScrollbar(true)
	
	local AList = vgui.Create( "DPanelList" )
	AList:SetAutoSize(true)
	AList:SetSpacing(5)
	AList:EnableVerticalScrollbar(true)
	
	Col:SetContents(AList)
	Ammo:SetContents(WList)
	
	local BuyShotgun = vgui.Create("DButton")
    BuyShotgun:SetText("Shotgun")
	function BuyShotgun:OnMousePressed()
		RunConsoleCommand("buy_shotgun")
	end
	WList:AddItem(BuyShotgun)
	
	local BuyPistol = vgui.Create("DButton")
	BuyPistol:SetText("100: Pistol")
	function BuyPistol:OnMousePressed()
		RunConsoleCommand("buy_pistol")
	end
	WList:AddItem(BuyPistol)
	
	local BuyM4 = vgui.Create("DButton")
	BuyM4:SetText("300: M4")
	function BuyM4:OnMousePressed()
		RunConsoleCommand("buy_m4")
	end
	WList:AddItem(BuyM4)
	
	local BuyRifleAmmo = vgui.Create("DButton")
	BuyRifleAmmo:SetText("100: Assult rifle ammo")
	function BuyRifleAmmo:OnMousePressed()
		RunConsoleCommand("buy_rif_ammo")
	end
	
	local BuyPistolAmmo = vgui.Create("DButton")
	BuyPistolAmmo:SetText("Pistol ammo")
	function BuyPistolAmmo:OnMousePressed()
		RunConsoleCommand("buy_pist_ammo")
	end
	AList:AddItem(BuyPistolAmmo)
	
	local BuyShotgunAmmo = vgui.Create("DButton")
	BuyShotgunAmmo:SetText("Shotgun Ammo")
	function BuyShotgunAmmo:OnMousePressed()
		RunConsoleCommand("buy_shtg_ammo")
	end
	AList:AddItem(BuyShotgunAmmo)
	
end

usermessage.Hook("MyMenu", MyMenu)

sh_player.lua


local meta = FindMetaTable("Player") --Get the meta table of player
 
function meta:AddMoney(amount)
	local current_cash = self:GetMoney()
	self:SetMoney( current_cash + amount )
end
 
function meta:SetMoney(amount)
	self:SetNetworkedInt( "Money", amount )
	self:SaveMoney()
end
 
function meta:SaveMoney()
	local cash = self:GetMoney()
	self:SetPData("money", cash)
end
 
function meta:SaveMoneyTXT()
	file.Write(gmod.GetGamemode().Name .."/Money/".. string.gsub(self:SteamID(), ":", "_") ..".txt", self:GetMoneyString())
end
 
function meta:TakeMoney(amount)
   --Add money function here
   self:AddMoney(-amount)
end
 
function meta:GetMoney()
	return self:GetNetworkedInt( "Money" )
end
 

Use this for your money system instead.

Ok, well that just chnges my money system, the problem still occors, EVERYONE gets ten dollars when someone dies, I just want the person who killed him to get the money not EVERYONE.

instead of RunConsoleCommand(“NPCKill”)

do

NPCKill(killer)

and get rid of concommand.Add(“NPCKill”)