Hey there everyone, recently I ran into a problem with this script where talking without a tag repeats your name twice
It looks like this:
this is set up so that your name color is dependent on your team color
It works completely fine when you have a tag like Owner or VIP
Here’s the code, a local script:
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
local ChatWindowConfig = TextChatService.ChatWindowConfiguration
local gradient = Instance.new("UIGradient")
gradient.Color = ColorSequence.new{
ColorSequenceKeypoint.new(0, Color3.fromRGB(252, 255, 94)),
ColorSequenceKeypoint.new(1, Color3.fromRGB(255, 151, 24))
}
local ownergradient = Instance.new("UIGradient")
ownergradient.Rotation = 90
ownergradient.Color = ColorSequence.new{
ColorSequenceKeypoint.new(0, Color3.fromRGB(134, 28, 255)),
ColorSequenceKeypoint.new(1, Color3.fromRGB(19, 0, 35))
}
local testergradient = Instance.new("UIGradient")
testergradient.Rotation = 90
testergradient.Color = ColorSequence.new{
ColorSequenceKeypoint.new(0, Color3.fromRGB(41, 255, 26)),
ColorSequenceKeypoint.new(1, Color3.fromRGB(13, 255, 0))
}
local testers = {
...
}
local function GetTeamColorHex(plr)
if plr and plr.Team then
local c = plr.TeamColor.Color
return string.format("#%02X%02X%02X",
math.floor(c.R * 255),
math.floor(c.G * 255),
math.floor(c.B * 255)
)
end
return "#FFFFFF"
end
TextChatService.OnChatWindowAdded = function(message)
local props = ChatWindowConfig:DeriveNewMessageProperties()
if message.TextSource then
local player = Players:GetPlayerByUserId(message.TextSource.UserId)
if not player then return props end
local teamColor = GetTeamColorHex(player)
local coloredName = string.format("<font color='%s'>%s:</font>", teamColor, player.DisplayName)
if player:GetAttribute("isVIP") and player.UserId ~= 3369010010 then
props.PrefixText = "[VIP]"
props.Text = string.format("%s %s", coloredName, message.Text)
props.PrefixTextProperties = ChatWindowConfig:DeriveNewMessageProperties()
gradient:Clone().Parent = props.PrefixTextProperties
elseif player.UserId == 33690100100 then
props.PrefixText = "[OWNER]"
props.Text = string.format("%s %s", coloredName, message.Text)
props.PrefixTextProperties = ChatWindowConfig:DeriveNewMessageProperties()
ownergradient:Clone().Parent = props.PrefixTextProperties
elseif testers[player.UserId] then
props.PrefixText = "[Tester🧪]"
props.Text = string.format("%s %s", coloredName, message.Text)
props.PrefixTextProperties = ChatWindowConfig:DeriveNewMessageProperties()
testergradient:Clone().Parent = props.PrefixTextProperties
else
props.Text = string.format("%s %s", coloredName, message.Text)
end
end
return props
end
Help would be greatly appreciated!
