Trouble with duplicating chat messages

  1. What do you want to achieve? Fix chat messages duplicating for whatever reason

  2. What is the issue? Screenshot by Lightshot

  3. What solutions have you tried so far? Tried looking for bugs, couldn’t find any.

player.Chatted:Connect(function(msg)
	if transmitting == true then
		script.Parent.Send:Play()
		game.ReplicatedStorage.Remotes.TransmitChat:FireServer(msg,"transmit")
		end
end)
-- server code

game.ReplicatedStorage.Remotes.TransmitChat.OnServerEvent:Connect(function(plr,msg,method)
	if method == "transmit" then
		for i,v2 in pairs(callsigns) do
			for i,v3 in pairs(v2) do
				if v3["Username"] == plr.Name then
					local message = v3["Callsign"].." - "..msg
					game.ReplicatedStorage.Remotes.TransmitChat:FireAllClients(message)
				end
			end
		end
	elseif method == "panic" then
		for i,v2 in pairs(callsigns) do
			for i,v3 in pairs(v2) do
				if v3["Username"] == plr.Name then

					game.ReplicatedStorage.Remotes.Panic:FireAllClients(v3["Callsign"])
				end
			end
		end
	elseif method == "dispatch" then
		for i,v2 in pairs(callsigns) do
			for i,v3 in pairs(v2) do
				if v3["Username"] == plr.Name then
					local message = "DISPATCH - "..msg
					game.ReplicatedStorage.Remotes.DispatchEvent:FireAllClients(message)
				end
			end
		end
	end
end)
2 Likes

the for loops might be firing the event multiple times, try adding return after every line that fires the event

Add a break/return when you finish your loop.

Code:

-- server code

game.ReplicatedStorage.Remotes.TransmitChat.OnServerEvent:Connect(function(plr,msg,method)
	if method == "transmit" then
		for i, v2 in callsigns do
			for i, v3 in v2 do
				if v3.Username == plr.Name then
					local message = v3.Callsign.." - "..msg
					game.ReplicatedStorage.Remotes.TransmitChat:FireAllClients(message)
					
					return
				end
			end
		end
	elseif method == "panic" then
		for i, v2 in callsigns do
			for i,v3 in v2 do
				if v3.Username == plr.Name then
					game.ReplicatedStorage.Remotes.Panic:FireAllClients(v3["Callsign"])
					
					return
				end
			end
		end
	elseif method == "dispatch" then
		for i, v2 in callsigns do
			for i, v3 in v2 do
				if v3.Username == plr.Name then
					local message = "DISPATCH - "..msg
					game.ReplicatedStorage.Remotes.DispatchEvent:FireAllClients(message)
					
					return
				end
			end
		end
	end
end)

Didn’t work, still duplicates for some people.

Could you show me the client code that receives TransmitChat?

Actually I think I found the issue, turns out if they submitted their callsign two times it would duplicate two times… Thought I fixed this 3 months ago but turns out it showed up again for some reason

Nevermind it’s still happening… It randomly happens to messages

Does this happen only for transmit?

I also need this: