Attempting To Use Variables For Color3

Hello, I’m trying to change a Color3 value using a variable.

My variables are pre-set using this local variable set.
image

image
My code looks for a message chatted by me, and then re-colors a, which was set previously as model:GetChildren().
image

Most of this code works as it should. However, Color3.fromRGB() is returning (0,0,0) when attempting to get Color value.
Everything else works completely as intended. The Color3 values are changed, and CurrentColor is changed. However, it’s all changed to black. How do I go about returning the proper Color value via a Color3Value class?

2 Likes

Are you using Color3Values? Also try putting print(red) just above a[i].Color = ... and see what it prints.

An image of my Color3Value class is shown in the above post. They are indeed Color3 RGB values.

Printing to output yields the proper result. There is no error, it is simply returning the Color3 value as (0,0,0)

1 Like

This is because when you get the Value of a Color3Value, it returns the RGB components as decimals between 0 and 1. Try changing Color3.fromRGB(red) to Color3.new(red) and see if it works.


The reason why you were getting 0, 0, 0 as your RGB values when you use fromRGB is because the numbers you get from ColorRed.Value are [0.592157, 0, 0]. As you can see, these are so close to 0 that they may as well be 0, because Color3.fromRGB takes in the colour components as numbers between 0 and 255.

2 Likes

This does return a decimal in output, but the thing I’m attempting to recolor remains black.
image

Did you use Color3.new(red) on both lines?
image

image
Yes, both use Color3.new()

I realised you would have to do it like this:

Color3.new(red.R, red.G, red.B)

Remove the Color3.new(). You can’t construct a Color3 out of another.

@Quackers337 that is redundant and is a waste of time

4 Likes

  local red = RedColor.Value

  for i = 1, #a do
      a[i].Color = red
      CurrentColor = red 
  end

you don’t need to use Color3.FromRGB when using Color3 values

3 Likes

Does this mean completely removing Color3 and using only the variable?
Such as a[i].Color = red

That is how you do it. You don’t need Color3.* to create a new instance of color3.

1 Like

Thank you, the method worked.
I appreciate everyone’s help.