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.
What the chat tags look like:
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.