Hi there! I have these powerups for my game and when people touch them, a gui displays the value of it and the color. I am using neon with one of them and I need the color to be orange, but to achieve the look of this I need to use dark orange. So the gui appears as dark orange, and I want it to be normal orange. I am trying to compare the color values of the player’s touch color and the dark orange color, but it just skips over it even though they clearly match, as I have printed the color at the end and it is the same as the dark orange.
script
if player.BCVCheck.Value.Color == Color3.new(0.627451, 0.372549, 0.207843) then --dark orange color
text.TextColor3 = Color3.new(1, 0.333333, 0) --normal orange
print("changed to the correct orange")
end
if player.BCVCheck.Value.Color ~= Color3.new(0.627451, 0.372549, 0.207843) then
text.TextColor3 = player.BCVCheck.Value.Color --any other color
end
print(text.TextColor3)
Is there a different method to this? What should I do differently?
You should use Color3.fromRGB instead of Color3.new because it provides numbers from 0 - 255 instead of 0 - 1. You can convert a Color3.new value to Color3.fromRGB by dividing it by 255.
-- a boolean function to compare the color3s
local function CompareColor3(base: Color3, toCompare: Color3) : boolean
local base_colors = { base.R , base.G, base.B } -- table to hold the original color3s
local comp_colors = { toCompare.R , toCompare.G, toCompare.B } -- table to
local verdict = {} -- table to hold whether other not each of them were the same
for index, col in ipairs(comp_colors) do -- uses an "ipairs" loop instead of "pairs" loop because this is numerical
if base_colors[index] == col then -- checks if the index of the base_colors table is the same
table.insert(verdict, true) -- add 1 true value to the verdict table
else
table.insert(verdict, false) -- add 1 false value to the verdict table
end
end
if table.find(verdict, false) then -- if one of them is false then it isn't the same
return false -- returns false
else
return true -- returns true
end
end
if CompareColor3(player.BCVCheck.Value.Color, Color3.new(0.627451/255, 0.372549/255, 0.207843/255)) then --dark orange color
text.TextColor3 = Color3.new(1, 0.333333, 0) --normal orange
print("changed to the correct orange")
end
if not CompareColor3(player.BCVCheck.Value.Color, Color3.new(0.627451/255, 0.372549/255, 0.207843/255)) then
text.TextColor3 = player.BCVCheck.Value.Color --any other color
end
print(text.TextColor3)