We all know by now that it's not what they say it is by 'random'..
So how are they calculating the color for our name?
We all know by now that it's not what they say it is by 'random'..
So how are they calculating the color for our name?
This is one of those very few questions I give a direct answer to, but I'm only doing this because just about every custom chat system on ROBLOX that I know of that implements this feature, uses the exact same method.
Basically, it's a combination between the length of the name, and each individual character's ASCII value. After it's gotten that information from within the for loop, well, the math below speaks for itself. Here's my version of it, where the name is the first parameter, and an array of Color3 values, is it's second:
local function GetLengthColor(String,ColorList)
local Result = 0 -- Final number to modulate the #ColorList from
for i = 1, #String do
local ASCII = String:sub(i,i):byte() -- Get the ASCII value of it's current character
local Comp = #str-i+1
if #String%2 == 1 then
Comp = Comp-1
end
if Comp%4 >= 2 then
ASCII = -ASCII
end
Result = Result+ASCII
end
return ColorList[Result%#ColorList+1] -- Return the index value from the ColorList.
end
Hope this is what you were looking for. I'm sorry to say that I don't know what colors ROBLOX uses for their speaker tags, but this is the correct sequence in which it's chosen from.
If you have any questions regarding how the function works, just let me know and I'll be happy to explain.
To add onto ScriptGuider's answer:
These are the colors:
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,
}
And this is the formula:
function getChatColor(pName)
return CHAT_COLORS[(GetNameValue(pName) % #CHAT_COLORS) + 1]
end
Taken from the core script for the Roblox chat system.
Whoops, looks like NullSenseStudio beat me to it with his comment
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
You could look at ROBLOX's GitHub repository for the current chat colors. https://github.com/ROBLOX/Core-Scripts/blob/master/CoreScriptsRoot/Modules/Chat.lua