workspace.Part.Color = Color3.new(100/255,100/255,100/255) workspace.Part.Value.Value = Color3.new(100/255,100/255,100/255) if workspace.Part.Color == workspace.Part.Value.Value then print'equal' end
Try this out, it will never print equal even though these are the exact same for some reason. It will work with any other color though, I don't understand? Just put a part in workspace and put a color3 value in it and run this in the command bar
So I did some testy test and found out some interesting things.
First it is important to remember that color3.new()
takes in number value from 0
to 1
. A color3.fromRGB
takes value from 0
to 255
.
-- [Declaration Section] local Baseplate = workspace.Baseplate; local Color = workspace.Color; -- [Initialization Section] Baseplate.Color = Color3.new(78/255, 34/255, 100/255); Color.Value = Color3.new(78/255, 34/255, 100/255); -- [Output Section] if Baseplate.Color == Color.Value then print("Similar!"); else print("Not Similar"); end;
I inserted a Color3Value
on Workspace
and currently am testing its value with Baseplate
's Color
.
When you run the code, you will notice that it prints Not Similar
. The problem is that the number/255
gives us decimal numbers. From my understanding, the Color3Value
takes in values from 0
to 255
.
But if you check the Color3Value
's Value
when running the game, you will notice that the value is actually the exact same as the one we are assigning with. Do take a look at this Image. If anyone could explain why that is happening, it would be appreciated.
Neverthless, the fix for your code would be to use Color3.fromRGB
when assigning values to Color3Value
.
-- [Declaration Section] local Baseplate = workspace.Baseplate; local Color = workspace.Color; -- [Initialization Section] Baseplate.Color = Color3.new(78/255, 34/255, 100/255); Color.Value = Color3.fromRGB(78, 34, 100); -- [Output Section] if Baseplate.Color == Color.Value then print("Similar!"); else print("Not Similar"); end;
The above example will print Similar
.
[EDIT]
@hiimgoodpack had answered that Color3.new()
way does not work because floating point errors. The if
conditional statement does not run because those two numbers do not exactly match. Credits to hiim.