Why is this code not working?



if ply:IsUserGroup() == "moderator" or ply:IsAdmin() then
	
	if ENF.Settings.EnableLogs == 1 then
	
		net.Start("Enforcer_Open_Menu")
		net.WriteTable(Enf_PropLogs)
		net.WriteTable(Enf_DeathLogs)
		net.WriteTable(Enf_DamageLogs)
		net.WriteDouble(1)
		net.Send(ply)
		
	else

		net.Start("Enforcer_Open_Menu")
		net.WriteTable(Enf_PropLogs)
		net.WriteTable(Enf_DeathLogs)
		net.WriteTable(Enf_DamageLogs)
		net.WriteDouble(0)
		net.Send(ply)	
	
	
end


So, only the admins can open the menu… not the moderators, please help me!

Either do ply:IsUserGroup(“moderator”) or ply:GetUserGroup() == “moderator”

Testing this out, will report when results come.

[editline]31st July 2015[/editline]

So, it’s still not working… The new code is as follows:



if ply:GetUserGroup() == "moderator" or ply:IsAdmin() then
	
	if ENF.Settings.EnableLogs == 1 then
	
		net.Start("Enforcer_Open_Menu")
		net.WriteTable(Enf_PropLogs)
		net.WriteTable(Enf_DeathLogs)
		net.WriteTable(Enf_DamageLogs)
		net.WriteDouble(1)
		net.Send(ply)
		
	else

		net.Start("Enforcer_Open_Menu")
		net.WriteTable(Enf_PropLogs)
		net.WriteTable(Enf_DeathLogs)
		net.WriteTable(Enf_DamageLogs)
		net.WriteDouble(0)
		net.Send(ply)	
	
	
	end
		
end


[editline]31st July 2015[/editline]

EDIT: Made code a little more readable.

Make yourself a moderator and do print( ply:GetUserGroup() )

It came as an error… Lol

Very informative!

When you debug code, you add print in every if statement and function around where your code doesn’t work. This way you can see in the console how far you get into it and can see what the problem is.
[lua]if ply:GetUserGroup() == “moderator” or ply:IsAdmin() then

print("Player is admin")
if ENF.Settings.EnableLogs == 1 then

	print("log is 1")
	net.Start("Enforcer_Open_Menu")
	net.WriteTable(Enf_PropLogs)
	net.WriteTable(Enf_DeathLogs)
	net.WriteTable(Enf_DamageLogs)
	net.WriteDouble(1)
	net.Send(ply)
	
else

	print("log is 0")
	net.Start("Enforcer_Open_Menu")
	net.WriteTable(Enf_PropLogs)
	net.WriteTable(Enf_DeathLogs)
	net.WriteTable(Enf_DamageLogs)
	net.WriteDouble(0)
	net.Send(ply)	


end

end[/lua]
Then run the code again in your game and check your server output. If none of them print, it’s an issue with the top part. If the admin prints and one of the logs too, you know that it sent the net messages. In this case, head to the client and do prints to see if you received it.

Always do this to figure out at exactly which statement it fails.

Is the command running on a hook or is that the whole code? Did you define ‘ply’ in your function?



if ply:GetUserGroup() == "moderator" or ply:IsAdmin() then
		net.Start("Enforcer_Open_Menu")
		net.WriteTable(Enf_PropLogs)
		net.WriteTable(Enf_DeathLogs)
		net.WriteTable(Enf_DamageLogs)
		net.WriteDouble(ENF.Settings.EnableLogs)
		net.Send(ply)		
end


You are using the same code twice with only one value changing that also is the variable you compare against, you could just do this and reduce the code written

Wouldn’t it also be far more efficient to use net.SendBit and net.ReadBit, in place of Double?

Not by much in this case but indeed more efficient.

Yeah, “far more”, was a bit generous of me I guess.