Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you get the player chat tag color?

How do you get the player chat tag color (the color for like [Player1]:) and stuff. I've seen people get it before, so I know its possible, but I want to know how. I've tried player.TeamColor but that returns white because the player team is technically 'neutral' Can anybody please help?

1 answer

✓ Accepted answer

This is the internal function used to compute the chat color of each player (taken from the core chat script):

local CHAT_COLORS = {
	Color3.new(253/255, 41/255, 67/255), -- BrickColor.new("Bright red").Color,
	Color3.new(1/255, 162/255, 255/255), -- BrickColor.new("Bright blue").Color,
	Color3.new(2/255, 184/255, 87/255), -- BrickColor.new("Earth green").Color,
	BrickColor.new("Bright violet").Color,
	BrickColor.new("Bright orange").Color,
	BrickColor.new("Bright yellow").Color,
	BrickColor.new("Light reddish violet").Color,
	BrickColor.new("Brick yellow").Color,
}

local function GetNameValue(pName)
	local value = 0
	for index = 1, #pName do
		local cValue = string.byte(string.sub(pName, index, index))
		local reverseIndex = #pName - index + 1
		if #pName%2 == 1 then
			reverseIndex = reverseIndex - 1
		end
		if reverseIndex%4 >= 2 then
			cValue = -cValue
		end
		value = value + cValue
	end
	return value
end

function ComputeChatColor(pName)
	return CHAT_COLORS[(GetNameValue(pName) % #CHAT_COLORS) + 1]
end

2 comments

0

That's because it is taken from the core scripts, you have to use this algorithm to gaurentee that you produce the same color as Roblox would

This discussion is preserved as it was. New answers, comments, and votes are closed.