Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

is there a way of Subtracting Color3?

Asked by 8 years ago
Edited 8 years ago

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

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

It doesn't work.

Do I use colorsequence or someething?

I don't understand.

1 answer

Log in to vote
2
Answered by
cabbler 1942 Moderation Voter
8 years ago
Edited 8 years ago

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.

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

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

1--(these variables can be anything)
2local original = Color3.new(1,1,1)
3local goal = Color3.new(0,0,0)
4local inc = 1/100
5 
6for i=0,1,inc do
7    wait()
8    gui.BackgroundColor3 = original:lerp(goal,i)
9end

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!

0
What is lerp? dakanji123 97 — 8y
0
What does it do? dakanji123 97 — 8y
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 dakanji123 97 — 8y
0
Lerp returns a certain point towards a goal value, and it's not instant if you do a loop like I showed you. cabbler 1942 — 8y
View all comments (4 more)
0
Please teach me how lerp works. Show me examples dakanji123 97 — 8y
0
In Gui.BackgroundColor3 = original:lerp(goal,i). Why is " i " there? dakanji123 97 — 8y
0
Can you explain to me how that script works? dakanji123 97 — 8y
Ad

Answer this question