Ply = Nil Value Error Help

Hello,

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") .. ")"
end

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

	KillerName = killer:GetDriver():Nick()

end

if killer == pl then

	KillerName = "Himself"
	WeaponName = "suicide trick"

end

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

end
hook.Add(“PlayerDeath”, “logDeathsKills”, logDeathsKills)
[/lua]

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
    [/lua]

[editline]22nd July 2013[/editline]

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