Player name also appearing on bubble chat

I AM USING TEXTCHATSERVICE

As the title says, when I chat in the chat, it appears on the bubblechat aswell as the chat. But it’s different. Here is what I mean:

As you can see, in the chat it works, but on the bubble chat it appears my name with the color. How can I fix that?

CODE:

local textChatService = game:GetService("TextChatService")
local groupService = game:GetService("GroupService")
local players = game:GetService("Players")

local chatWindowConfiguration = textChatService.ChatWindowConfiguration

local function getPlayerName(player: Player)
	return player.Name
end

textChatService.OnIncomingMessage = function(message: TextChatMessage)
	local properties = Instance.new("TextChatMessageProperties")

	if message.TextSource then
    local player = players:GetPlayerByUserId(message.TextSource.UserId)
    if player then
        local rankInGroup = player:GetRankInGroup(8423759)

        if rankInGroup == 255 then
            properties.PrefixText = "<font color='#ad3335'><b>[Owner]</b></font>"
            properties.Text = string.format("<font color='#d84042'>%s</font>", message.PrefixText) .. " " .. message.Text
        elseif rankInGroup == 9 then
            properties.PrefixText = "<font color='#d53f41'><b>[Manager]</b></font>"
            properties.Text = string.format("<font color='#d54e50'>%s</font>", message.PrefixText) .. " " .. message.Text
        elseif rankInGroup == 8 then
            properties.PrefixText = "<font color='#9837d5'><b>[Developer]</b></font>"
            properties.Text = string.format("<font color='#bc49ff'>%s</font>", message.PrefixText) .. " " .. message.Text
        elseif rankInGroup == 7 then
            properties.PrefixText = "<font color='#0baaff'><b>[Admin]</b></font>"
            properties.Text = string.format("<font color='#00c3ff'>%s</font>", message.PrefixText) .. " " .. message.Text
        elseif rankInGroup == 6 then
            properties.PrefixText = "<font color='#c26802'><b>[Moderator]</b></font>"
            properties.Text = string.format("<font color='#ff8902'>%s</font>", message.PrefixText) .. " " .. message.Text
        elseif rankInGroup == 1 then
            properties.PrefixText = "<font color='#5ec725'><b>[Gang]</b></font>"
            properties.Text = string.format("<font color='#a7ff34'>%s</font>", message.PrefixText) .. " " .. message.Text
        end
    end
end

return properties
end
1 Like

I haven’t managed to fix this, any help would be great! :smile:

I think I see the issue but I do not know how to fix it.

Hello. This is getting quite frustrating, as this is a persisting issue. I need help.

I suppose that it’s the:

Maybe try removing it?

1 Like

I’ll try it.

EDIT: Wait no I just realised that is for the actual chat tag. Can you provide me a script of what you mean?

I have edited the script, the bubble chat works, but in the text chat window it will make the message appear twice after the player name, it goes like this: [Manager] TeamDreams123: test test

Here’s the code:

local textChatService = game:GetService("TextChatService")
local players = game:GetService("Players")

local chatWindowConfiguration = textChatService.ChatWindowConfiguration

local function getPlayerName(player: Player)
	return player.Name
end

textChatService.OnIncomingMessage = function(message: TextChatMessage)
	local properties = Instance.new("TextChatMessageProperties")

	if message.TextSource then
		local player = players:GetPlayerByUserId(message.TextSource.UserId)
		if player then
			local playerName = getPlayerName(player)
			local rankInGroup = player:GetRankInGroup(8423759)

			if rankInGroup == 255 then
				local prefix = "<font color='#ad3335'><b>[Owner]</b></font>"
				local formattedMessage = string.format("<font color='#d84042'>%s: %s</font>", playerName, message.Text)
				properties.PrefixText = prefix .. " " .. formattedMessage
			elseif rankInGroup == 9 then
				local prefix = "<font color='#d53f41'><b>[Manager]</b></font>"
				local formattedMessage = string.format("<font color='#d54e50'>%s: %s</font>", playerName, message.Text)
				properties.PrefixText = prefix .. " " .. formattedMessage
			elseif rankInGroup == 8 then
				local prefix = "<font color='#9837d5'><b>[Developer]</b></font>"
				local formattedMessage = string.format("<font color='#bc49ff'>%s: %s</font>", playerName, message.Text)
				properties.PrefixText = prefix .. " " .. formattedMessage
			elseif rankInGroup == 7 then
				local prefix = "<font color='#0baaff'><b>[Admin]</b></font>"
				local formattedMessage = string.format("<font color='#00c3ff'>%s: %s</font>", playerName, message.Text)
				properties.PrefixText = prefix .. " " .. formattedMessage
			elseif rankInGroup == 6 then
				local prefix = "<font color='#c26802'><b>[Moderator]</b></font>"
				local formattedMessage = string.format("<font color='#ff8902'>%s: %s</font>", playerName, message.Text)
				properties.PrefixText = prefix .. " " .. formattedMessage
			elseif rankInGroup == 1 then
				local prefix = "<font color='#5ec725'><b>[Gang]</b></font>"
				local formattedMessage = string.format("<font color='#a7ff34'>%s: %s</font>", playerName, message.Text)
				properties.PrefixText = prefix .. " " .. formattedMessage
			end
		end
	end

	return properties
end

Try this.

local textChatService = game:GetService("TextChatService")
local players = game:GetService("Players")

local chatWindowConfiguration = textChatService.ChatWindowConfiguration

local function getPlayerName(player: Player)
	return player.Name
end

textChatService.OnIncomingMessage = function(message: TextChatMessage)
	local properties = Instance.new("TextChatMessageProperties")

	if message.TextSource then
		local player = players:GetPlayerByUserId(message.TextSource.UserId)
		if player then
			local playerName = getPlayerName(player)
			local rankInGroup = player:GetRankInGroup(8423759)

			if rankInGroup == 255 then
				local prefix = "<font color='#ad3335'><b>[Owner]</b></font>"
				local formattedMessage = string.format("<font color='#d84042'>%s:</font>", playerName)
				properties.PrefixText = prefix .. " " .. formattedMessage
			elseif rankInGroup == 9 then
				local prefix = "<font color='#d53f41'><b>[Manager]</b></font>"
				local formattedMessage = string.format("<font color='#d54e50'>%s:</font>", playerName)
				properties.PrefixText = prefix .. " " .. formattedMessage
			elseif rankInGroup == 8 then
				local prefix = "<font color='#9837d5'><b>[Developer]</b></font>"
				local formattedMessage = string.format("<font color='#bc49ff'>%s:</font>", playerName)
				properties.PrefixText = prefix .. " " .. formattedMessage
			elseif rankInGroup == 7 then
				local prefix = "<font color='#0baaff'><b>[Admin]</b></font>"
				local formattedMessage = string.format("<font color='#00c3ff'>%s:</font>", playerName)
				properties.PrefixText = prefix .. " " .. formattedMessage
			elseif rankInGroup == 6 then
				local prefix = "<font color='#c26802'><b>[Moderator]</b></font>"
				local formattedMessage = string.format("<font color='#ff8902'>%s:</font>", playerName)
				properties.PrefixText = prefix .. " " .. formattedMessage
			elseif rankInGroup == 1 then
				local prefix = "<font color='#5ec725'><b>[Gang]</b></font>"
				local formattedMessage = string.format("<font color='#a7ff34'>%s:</font>", playerName)
				properties.PrefixText = prefix .. " " .. formattedMessage
			end
		end
	end

	return properties
end

I have modified your script and tested it.
The reason this works is because we removed the message.Text in the formattedMessage. There is no need to put it in there if it already exists in message.Text.

To make it easier to understand, a message in chat will show up with the prefix text and message combined. SInce you are putting the text in the prefix text, it is shown
twice.

Also, you are using a lot of if statements. Try to do something to shorten them down.

1 Like

Alright.

Thank you! It worked. I marked your reply as the solution.

1 Like

No problem.

Also, to help you out, I have done this for you.

local textChatService = game:GetService("TextChatService")
local players = game:GetService("Players")

local chatWindowConfiguration = textChatService.ChatWindowConfiguration

local function getPlayerName(player: Player)
	return player.Name
end

local Tags = {
	[255] = {"<font color='#ad3335'><b>[Owner]</b></font>", "<font color='#d84042'>%s:</font>"},
	[9] = {"<font color='#d53f41'><b>[Manager]</b></font>", "<font color='#d54e50'>%s:</font>"},
	[8] = {"<font color='#9837d5'><b>[Developer]</b></font>", "<font color='#bc49ff'>%s:</font>"},
	[7] = {"<font color='#0baaff'><b>[Admin]</b></font>", "<font color='#00c3ff'>%s:</font>"},
	[6] = {"<font color='#5ec725'><b>[Gang]</b></font>", "<font color='#ff8902'>%s:</font>"},
	[1] = {"<font color='#5ec725'><b>[Gang]</b></font>", "<font color='#a7ff34'>%s:</font>"}
}

textChatService.OnIncomingMessage = function(message: TextChatMessage)
	local properties = Instance.new("TextChatMessageProperties")

	if message.TextSource then
		local player = players:GetPlayerByUserId(message.TextSource.UserId)
		if player then
			local playerName = getPlayerName(player)
			local rankInGroup = player:GetRankInGroup(8423759)

			if Tags[rankInGroup] then
				local prefix = Tags[rankInGroup][1]
				local formattedMessage = string.format(Tags[rankInGroup][2], playerName)
				properties.PrefixText = prefix .. " " .. formattedMessage
			end

		end
	end

	return properties
end

EDIT: oops i put in my own group id before :joy:
it’s fixed now

1 Like

That’s much better, shorter (and probably more performance increase)

1 Like