Hello! I’m making a ColorConverter
, and I have encountered a problem during testing. I convert color sequences to color3 by finding the average, but when I set a part’s color to the result of the conversion, the color is COMPLETELY different from the brick color. Here’s a picture to show you what I mean:
Just think of how different sand red and grey are!
Code snippet of the script requiring the module:
local sequence2 = colorConverter.Convert({{0, Color3.fromRGB(0, 0, 0)}, {0.25, Color3.fromRGB(255, 50, 50)}, {0.5, Color3.fromRGB(50, 255, 50)}, {0.75, Color3.fromRGB(50, 50, 255)}, {1, Color3.fromRGB(255, 255, 255)}}, "ColorSequence")
part1.Color = colorConverter.Convert(sequence2, "Color3")
print(part1.BrickColor.Color)
print(part1.Color)
and the function that the module uses:
local function ifColor3(color, toConvert)
if typeof(color) == "BrickColor" and toConvert == "Color3" then
local colorToConvert = color.Color
return colorToConvert
elseif typeof(color) == "ColorSequence" and toConvert == "Color3" then --This is what is running, everything here works
local toAdd = Color3.new(0, 0, 0)
for i, v in pairs(color.Keypoints) do
toAdd = Color3.new(toAdd.R+v.Value.R, toAdd.G+v.Value.G, toAdd.B+v.Value.B)
end
local r = ((toAdd.R*255)/#color.Keypoints)
local g = ((toAdd.G*255)/#color.Keypoints)
local b = ((toAdd.R*255)/#color.Keypoints)
local returnThis = Color3.fromRGB(r,g,b)
return returnThis
elseif typeof(color) == "table" and toConvert == "Color3" then
for i, v in pairs(color) do
table.insert(colorTable, v)
end
return Color3.fromRGB(colorTable[1], colorTable[2], colorTable[3])
else
error("Given invalid parameters")
end
end
Output:
18:25:51.167 | 0.584314, 0.47451, 0.466667 - Server - Script:8
18:25:51.167 | 0.478431, 0.478431, 0.478431 - Server - Script:9