Admin Console Message

Hello,

I am currently trying to just print a simple console message (Might change it later) of when an Admin leaves it prints a message in the server console.

for some reason I get



[ERROR] lua/autorun/admin_disconnect.lua:49: attempt to index global 'ply' (a nil value)
1. fn - lua/autorun/admin_disconnect.lua:49
2. unknown - addons/ulib/lua/ulib/shared/hook.lua:183


Heres the code:



function AdminLeave( )
	if ply:IsAdmin() then
		print( "An Admin has left" )
	end
end
hook.Add( "PlayerDisconnected", "playerDisconnected", AdminLeave )


Thanks!

You’ve got ‘pl’ in the function and then player before IsAdmin

change if player:IsAdmin() then

to if pl:IsAdmin() then

note: this will only print an admin has left to the admin that left not everyone on the server.

edit, ninja’d

Yes sorry. This was an old bit of code, I have updated it to the current code

You still have to change ply:IsAdmin() to pl:IsAdmin() since you havea pl in your function



[ERROR] lua/autorun/admin_disconnect.lua:49: attempt to index global 'pl' (a nil value)
1. fn - lua/autorun/admin_disconnect.lua:49
2. unknown - addons/ulib/lua/ulib/shared/hook.lua:183


ok so now you changed, function AdminLeave(pl ) to AdminLeave()

put pl back in the function like this

function AdminLeave(pl)
if pl:IsAdmin() then



function AdminLeave(pl)
	if pl:IsAdmin() then
		print( "An Admin has left" )
	end
end
hook.Add( "PlayerDisconnected", "playerDisconnected", AdminLeave )


No errors, and no Print function

[editline]23rd September 2014[/editline]

SOLVED

WASN’T ADMIN ON SERVER. Thanks Invule