TextChatService message duplication

Hello, I’ve been encountering issue with duplication of chat message in text chat (it doesn’t affects bubble chat)

When I’m trying to send a message, it duplicates it when my script should replace it instead
before
after

  -- Chat
  
local Users = require(ReplicatedStorage.Modules:WaitForChild("GameManager").Users)

TextChatService.OnIncomingMessage = function(message: TextChatMessage)
  local properties = Instance.new("TextChatMessageProperties")
  
  if message.TextSource then
    local player = game.Players:GetPlayerByUserId(message.TextSource.UserId)
    
    -- checks if user is in table
    if Users[player.UserId] then
      properties.PrefixText = "<font color='" .. Users[player.UserId].RankColor .. "'>" .. Users[player.UserId].Rank .. "</font> " .. message.PrefixText .. "<font color='" .. Users[player.UserId].RankTextColor .. "'>  " .. message.Text .. "</font>"
    end
    print(message.PrefixText .. message.Text)
  end
  
  return properties
end

How can I fix this?

1 Like

If I’m not clear enough - I’m trying to change text color of the player, and I achieved it, but it also sends original message too, I can’t understand what should I even do to prevent it

you probably repeat it somewhere, or it does not change property fully

I didn’t repeat it, probably it doesn’t change property fully, but my question is how do I remove the duplication (after edited message)

I’m not sure since I never had that problem (I was making prefix before name only)

I used to only make prefix (rank) before name too, but I wanted to try making rank text color, I didn’t succeed with that as you see

1 Like

Let me find it and I will send you

I have a modules inside of script that handles chat prefixes, it returns this
Name of module is group rank

return {
    Color = "#0000ff",
    Name = "Tester"
}

And how I add prefix to player’s name

TextChatService.OnIncomingMessage = function(message)
    if not message.TextSource then return end
    local newMessageProperties = Instance.new("TextChatMessageProperties")

    local User = message.TextSource.UserId
    local Player = Players:GetPlayerByUserId(User)
    
-- I dont think you need vip one
    --[[local OwnsVip = CheckOwnedGamepass(Player, 860504971)
    if OwnsVip then
        newMessageProperties.PrefixText = "<font color = '".. AllTags["VIP"]["Color"] .."'>[".. AllTags["VIP"]["Name"] .."] </font>" .. message.PrefixText
    end]]

    local PlrGroupRank = tostring(Player:GetRankInGroup(34319502))
    if AllTags[PlrGroupRank] then
        newMessageProperties.PrefixText = "<font color = '".. AllTags[PlrGroupRank]["Color"] .."'>[".. AllTags[PlrGroupRank]["Name"] .."] </font>" .. message.PrefixText
    end

    return newMessageProperties
end

AllTags is table containing all modules inside this script (I mentioned how they look above and their name too)

Your script affects only what is before message (prefix), and doesn’t touch the part of the message itself, I guess my best I can do is just not to color the message

I just dont understand what you want, but you can make thing based off this

изображение

Roblox’s AI generated the name color change, which was PrefixText
I changed it to Text and it works

local TextChatService = game:GetService("TextChatService")

TextChatService.OnIncomingMessage = function(message)
	local properties = Instance.new("TextChatMessageProperties")
	properties.Text = "<font color='#00ff00'>["..message.Text.."]</font>"
	return properties
end

You can remove the [ and ] if you want
I’m still not sure if this what you wanted

WAIT, I JUST REALIZED MY MISTAKE
Thank you so much for pointing out on properties.Text feature, I’ve been trying to use properties.PrefixText all time

1 Like

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