chat.AddText in networking called twice, IsFirstTimePredicted() always false

I’m trying to trigger the server to send the client a message to print in their chat when a keyword is said.

It’s sent through

Serverside



util.AddNetworkString("FAQ_sendClientFAQInfo")

net.Start("FAQ_sendClientFAQInfo")
    net.WriteString(v[2])
net.Send(ply)


Clientside



net.Receive("FAQ_sendClientFAQInfo", function(len, serv)
--	if not IsFirstTimePredicted() then return end <-- Always returns false
	print(IsFirstTimePredicted())                          -- false
	local str 	= net.ReadString()                        -- "Seeing errors? Type /addons to get the textures!"
	surface.PlaySound(FAQ_sound)                      -- "common/wpn_select.wav"
	timer.Simple(0.1, function() chat.AddText(FAQ_textColor, ("FAQ: "..str)) end)
end)


Chat

Console

What can I do to fix this? Or am I misusing IsFirstTimePredicted()?

TO CLARIFY, net.Send() is sending the message ONCE
net.Receive() is reading the message TWICE

The way you used v[2] in the server-side code leads me to believe you’re most likely using it within a loop / function, if that were the case it’d be useful if you posted the whole thing rather than just that portion you provided.

Serverside



util.AddNetworkString("FAQ_sendClientFAQInfo")

function FAQ_CheckMessage(ply, text, isTeam)
	if isTeam == true and FAQ_teamEnabled == false then return end

	for k,v in pairs(FAQ_triggerWords) do
		if string.find(text, v[1]) then
			net.Start("FAQ_sendClientFAQInfo")
				net.WriteString(v[2])
			net.Send(ply)
		end
	end
end

hook.Add("PlayerSay", "FAQ Check Message", FAQ_CheckMessage)


Shared



FAQ_triggerWords	= {
	{"errors", "Seeing errors? Type /addons to get the textures!"}
}


You don’t need to check if it’s the first time.

I forgot to mention, when I don’t the net message is sent once, but received twice.
Look at the chat picture to see what I mean

Because you are sending it twice.


for k,v in pairs(FAQ_triggerWords) do

Get it out of the loop.

And why even have a loop in the first place? I mean that table is quite useless imo…

There’s only one item, so why would it loop twice?
EDIT I put a print(“Hello world”) next to the net.Send() on the server side and it’s only called once. The net message is sent ONCE but the client reads it TWICE. On client side in net.Receive() if I put a print(“Hello world”) it prints twice.

[editline]19th August 2015[/editline]

I plan on adding more items as that table is a configuration of the addon.

Add a break after you call net.Send

That did the trick! Thanks