Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

is there a way of Subtracting Color3?

I'm trying to change the color of a GUI while subtracting.

The current "BackgroundColor3" is (255, 255, 255)

I'm trying to minus 1, 255 times from the background color to change the color 3 black. I already tried

This assume that "Gui" is already defined

for i = 1, 255 do
	wait(0)
Gui.BackgroundColor3 = Gui.BackgroundColor3 - Color3.new(1, 1, 1)

It doesn't work.

Do I use colorsequence or someething?

I don't understand.

1 answer

Color3 is not Vector3; it is not a math object. So you can't do math with it, and hopefully you do not have to . . .

Here, since you simply go from white to black, you should make use of the "i" in the loop.

for i = 255,0,-1 do
    wait()
    Gui.BackgroundColor3 = Color3.fromRGB(i,i,i)
end

However in more complex situations you are almost always need to use lerp. It would look like this.

--(these variables can be anything)
local original = Color3.new(1,1,1)
local goal = Color3.new(0,0,0)
local inc = 1/100

for i=0,1,inc do
    wait()
    gui.BackgroundColor3 = original:lerp(goal,i)
end

Lastly, if you really have to do actual math with the RGB values, which should be a last resort, simply take them out! i.e. Vector3.new(color.r, color.g, color.b)

Hope I helped!

8 comments

0

What is lerp?

0

What does it do?

0

I'm trying to turn that color(255, 255, 255) slowly down to (0,0,0) black. Not just instantly lerp it to black

0

Lerp returns a certain point towards a goal value, and it's not instant if you do a loop like I showed you.

0

Please teach me how lerp works. Show me examples

0

In Gui.BackgroundColor3 = original:lerp(goal,i). Why is " i " there?

0

Can you explain to me how that script works?

This discussion is preserved as it was. New answers, comments, and votes are closed.