Ply = Nil Value Error Help


I am getting this error: [[ERROR] lua/autorun/server/modes/mode_global.lua:25: attempt to index local ‘ply’ (a nil value)]

Here is my code

[lua]function logDeathsKills(pl, weapon, killer, ply)

local KillerName = (killer:IsPlayer() and killer:Nick()) or tostring(killer)

local WeaponName = IsValid(weapon) and ((weapon:IsPlayer() and IsValid(weapon:GetActiveWeapon()) and weapon:GetActiveWeapon():GetClass()) or weapon:GetClass()) or "unknown"
if IsValid(weapon) and weapon:GetClass() == "prop_physics" then
	WeaponName = weapon:GetClass() .. " (" .. (weapon:GetModel() or "unknown") .. ")"

if killer:IsVehicle() and killer:GetDriver():IsPlayer() then 

	KillerName = killer:GetDriver():Nick()


if killer == pl then

	KillerName = "Himself"
	WeaponName = "suicide trick"


ELS:Log(""..ply:GetRoleString().."" .. " was killed by " .. KillerName .. " who was a "..killer:GetRoleString().." and was killed with a " .. WeaponName.."")

hook.Add(“PlayerDeath”, “logDeathsKills”, logDeathsKills)

Basically it states:

place the code in lua tags

there you go, and sorry about that.

Change ply to pl.

PlayerDeath takes three arguments, the fourth argument you have is useless and will equal to nil.

Now with that, it fixed that but now I get:

[lua][ERROR] lua/autorun/server/sv_log.lua:82: bad argument #1 to ‘WriteInt’ (number expected, got nil)

  1. WriteInt - [C]:-1
  2. Log - lua/autorun/server/sv_log.lua:82
  3. fn - lua/autorun/server/modes/mode_global.lua:25
  4. unknown - addons/ulib/lua/ulib/shared/hook.lua:183

[editline]22nd July 2013[/editline]

Never mind I got it. Thank you so much for the help man!