Problem with admin detector script?

Ok so yesterday I made an admin detector script that is supposed to alert you when an admin/superadmin/owner joins the server, via a sound alert and a text alert, and then also lists the admins that are currently on the server. The script consists of two functions. The second function (ListAdmins) of the script simply outputs, in text, the current admins on the server and also what their rank is. This one works fine, I bind the concommand to a key and does what’s specified; but the first function (AdminAlert) doesn’t do anything when an admin joins. It doesn’t give me any errors in console, says it’s working fine. I’m kind of new to lua here so I’m not sure if I left something out in the function or put the wrong thing in somewhere. But yeah, can anyone here find the problem I’m having trouble with in the script? Thanks



function AdminAlert()
local ply = LocalPlayer()
	for k, v in pairs( player.GetAll() ) do
		if v:IsAdmin() or v:IsSuperAdmin() or v:IsUserGroup( "Admin" ) or v:IsUserGroup( "Super Admin" ) or v:IsUserGroup( "Owner" ) then
			ply:PrintMessage( HUD_PRINTTALK, "Admin Alert!" )
			ply:PrintMessage( HUD_PRINTTALK, "Admins: "..v:Nick().."." )
			surface.PlaySound( "ambient/robot_admin.mp3" )
		end	
	end
end
hook.Add( "PlayerInitialSpawn", "AdminAlert", AdminAlert )


function ListAdmins()
local ply = LocalPlayer()
	for k, v in pairs( player.GetAll() ) do
		if v:IsAdmin() or v:IsUserGroup( "Admin" ) then
			ply:PrintMessage( HUD_PRINTTALK, "Admins: "..v:Nick().."." )
		elseif v:IsSuperAdmin() or v:IsUserGroup( "Super Admin" ) then
			ply:PrintMessage( HUD_PRINTTALK, "Super Admins: "..v:Nick().."." )
		elseif v:IsUserGroup( "Owner" ) then
			ply:PrintMessage( HUD_PRINTTALK, "Owner: "..v:Nick().."." )
		elseif v:IsAdmin() == "" and v:IsSuperAdmin() == "" and v:IsUserGroup( "Admin" ) == "" and v:IsUserGroup( "Super Admin" ) == "" and v:IsUserGroup( "Owner" ) == "" then	
			ply:PrintMessage( HUD_PRINTTALK, "There are no admins on this server!" )
		end	
	end
end
concommand.Add( "muffin_sayalladmins", ListAdmins )


Hi,
‘PlayerInitialSpawn’ is a special kind of function and because of it, you don’t need to use a ‘for loop’, you just need to list it as an argument. When playing the sound, we are going to broadcast the lua playsound to ALL players so they know as well as create a fancy chat message!

Try dropping this in your lua/autorun folder.
[lua]
if ( SERVER ) then
hook.Add( “PlayerInitialSpawn”, “AlertPlayers”, function( ply ) – GET THE FUNCTION AND PLAYER VARIABLE
BroadcastLua( ‘surface.PlaySound( “PATHTOSOUND” )’ ) – Broadcasts the Sound to ALL players
umsg.Start( “GOPLAY” ) – START IT
umsg.String( “An Admin, “…ply:Nick()…”, has Joined the Server!” ) – THIS IS OUR MESSAGE
umsg.End() – SEND THAT SHIT
end )
end

if ( CLIENT ) then
usermessage.Hook( “GOPLAY”, function( data ) – Gets the UMSG and it’s data
chat.AddText( Color( 255, 255, 255 ), data:ReadString() ) – Prints the String in White text
end )
end
[/lua]

Please stop using usermessages.

oh crap i forgot to say it’s a clientside-only script. So do I just do if( CLIENT ) hook.Add yada yada…?

If you researched before asking this question you would realise that the “PlayerInitialSpawn” hook is serverside only.

I never knew that O.o, idk I thought it was both client and server for some reason :confused: thx