Help with TEAM restriction on chat command

Hi i’m trying to restrict a rdm command that I am using for my server. I want only a certain job, such as a thief to be able to use this command and if the player is not a thief then the return is “You cannot use this command!” This is in my lua/Autorun on my dedicated server. Here is the code.


if SERVER then
util.AddNetworkString( "rdmcall")
local function SendPartyMessage(ply, text)
local RDMcaller = ply:Nick()
net.Start("rdmcall")
net.WriteString(RDMcaller)
net.Send(player.GetAll())
end

hook.Add( "PlayerSay", "RDMcallin", function(ply,text)
if text == "/rdm" then  
ServerLog("[RDM] "..ply:Nick() .."
")
SendPartyMessage(ply, text)
return ""
end
end)
end

if CLIENT then
net.Receive("rdmcall", function(len, CLIENT)
local RDMcaller = net.ReadString()
local ply = LocalPlayer()
chat.AddText( Color(0,0,0), "[RDM] ",  Color(128,128,128), RDMcaller..": ", Color(255,255,255), "Called A RDM!")
else
chat.AddText( Color(0,0,0), "[RDM] ",  Color(128,128,128), "Someone"..": ", Color(255,255,255), "Called A RDM!")	
end
end)
end

I am lost on how to team restrict this, I have tried the following code aswell.


if CLIENT then
net.Receive("rdmcall", function(len, CLIENT)
local RDMcaller = net.ReadString()
local ply = LocalPlayer()
		if ply:Team() ~= TEAM_THIEF then
		ply:ChatPrint( "You canot use this command!" )
		elseif ply:Team() == TEAM_THIEF then
		chat.AddText( Color(0,0,0), "[RDM] ",  Color(128,128,128), "Someone"..": ", Color(255,255,255), "Called A RDM!")
		elseif ply:IsSuperAdmin() then
		chat.AddText( Color(0,0,0), "[RDM] ",  Color(128,128,128), RDMcaller..": ", Color(255,255,255), "Called A RDM!")
		end
	end)
end

I’m very new, so i suppose i’m missing something super obvious, any help would be greatly appreciated!

You want to check if the player’s job is a thief in the PlayerSay hook. Stop everything there if they are not a thief.

Ok, I tried that here,


hook.Add( "PlayerSay", "RDMcallin", function(ply,text)
if text == "/rdm" and ply:Team() == "TEAM_THIEF" then
ServerLog("[RDM] "..ply:Nick() .."
")
SendPartyMessage(ply, text)
return ""
end
end)
end

Also I tried it a few other ways, is my job check wrong, or am I not declaring a certain variable? Whenever i use the “ply:Team() == TEAM_THIEF” It seems to be ignored.

Try debugging your code. For example, at the beginning of that hook, do something like:
[lua]
print("debug testing: "…tostring(ply:Team()))
[/lua]

Join the game, become a thief, and see if that returns the string you are comparing the players team to.