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
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.
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
it’s fixed now