Incoming Message triggers twice in one message in my chat tag script

Incoming Message triggers twice in one message in my chat tag script

For some reason when I send a message in chat, my incoming message function triggers twice and I can’t find out why.
image

What the chat tags look like:
image
image

My local script inside of starterGUI:

local TCS = game:GetService("TextChatService")
local rp = game:GetService("ReplicatedStorage")
local modules = rp:WaitForChild("Modules")
local players = game:GetService("Players")

local chatModule = require(modules:WaitForChild("ChatTagModule"))

local player = players.LocalPlayer

TCS.OnIncomingMessage = function(message: TextChatMessage)
	local properties = Instance.new("TextChatMessageProperties")
	print("Triggered")
	if message.TextSource then
		local plr = players:GetPlayerByUserId(message.TextSource.UserId)
		for roleName , roles in chatModule do
			for _, id in roles do
				if plr.UserId == id then
					print(id)
					if roleName == "Lead_Developer" then	
						properties.PrefixText = "<font color='#750000'>[Lead Developer]</font> " .. message.PrefixText
					elseif roleName == "Developers" then
						
						properties.PrefixText = "<font color='#FFF300'>[Developer]</font> " .. message.PrefixText
					elseif roleName == "Admins" then
						
						properties.PrefixText = "<font color='#9B00FF'>[Admin]</font> " .. message.PrefixText
					elseif roleName == "Testers" then
						
						properties.PrefixText = "<font color='#00D4FF'>[Tester]</font> " .. message.PrefixText
					end
					
				end
			end
		end
	end
	return properties
end

Don’t worry about the module, it just has all the players with chat tags stored inside a dictionary.

Per the documentation from TextChannel | Documentation - Roblox Creator Hub

When bound to the client sending a message, this callback is run twice; first when the message is initially sent and received locally, and again when the client receives the result of the filtered message from the server.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.