ply:Team() not working

hello im new to lua, in fact this is the first lua code I have modded more than just adding a bunch of zeros on a rocket launcher’s damge…
So I’m editing DarkRP for a news job. I want the NEWS_TEAM to be the only one to use the “/advert” command. So i have tryed to edit the code but i got stuck in the cl_init.lua



	if GetGlobalInt("alltalk") == 0 then
		if string.sub(text, 1, 2) == "//" or string.sub(string.lower(text), 1, 4) == "/ooc" or string.sub(string.lower(text), 1, 4) == "/a" then
			HearMode = "talk through OOC"
		elseif string.sub(string.lower(text), 1, 7) == "/advert" and ply:Team() == TEAM_NEWS then
			HearMode = "advert"
		end
	end


Thanks for anyone who helps.

Hmmm… The “Advert” Doesn’t Have The / Try “/Advert” Maybe that will work. Never ran into this problem as I have never desired to it… So not experienced with it.

This looks clientside, isn’t it.
If it is, try replacing ply with LocalPlayer().

ply isn’t a special keyword, it’s just a naming convention most people use for any variable that should contain a player, that’s why you see it about everywhere. When you are outside of any function, or where you don’t know which player should be concerned by that function, you need to retrieve all the players who should be concerned by whatever you are trying to do.

Usually, when you are running something clientside (in clientside files, which usually start with cl_, or in shared files), the concerned player is yourself, and you can access that player using LocalPlayer().

Disregard this.

We’re going to need some output.
print(“EVENT CALLED”)
print(TEAM_NEWS)
print(ply)
print(ply:Team())
print(“CONDITION PASSED”)
print(whatever)

No.

Yeah, your right. That’s not the problem.

Sorry :3

[editline]hai[/editline]

[lua]function PlayerAdvertise(ply, args)
if args == “” then return “” end
for k,v in pairs(player.GetAll()) do
local col = team.GetColor(ply:Team())
TalkToPerson(v, col, LANGUAGE.advert …ply:Nick(), Color(255,255,0,255), args, ply)
end
return “”
end
AddChatCommand("/advert", PlayerAdvertise)[/lua]

Main.lua, that’s what you are meant to be editing.
So, that would be

[lua]function PlayerAdvertise(ply, args)
if args == “” then return “” end
if ply:Team() != TEAM_NEWS then return “” end

for k,v in pairs(player.GetAll()) do
	local col = team.GetColor(ply:Team())
	TalkToPerson(v, col, LANGUAGE.advert ..ply:Nick(), Color(255,255,0,255), args, ply)
end
return ""

end
AddChatCommand("/advert", PlayerAdvertise)[/lua]

Please correct me if I am wrong.

Thank you with the LocalPlayer() it worked perfectly and i used a mix of what Jamie sayed and what i had for the main folder and works perfectly. :smiley: I’m happy!