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 7 years ago
Edited 7 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

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

Log in to vote
2
Answered by
cabbler 1942 Moderation Voter
7 years ago
Edited 7 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.

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!

0
What is lerp? dakanji123 97 — 7y
0
What does it do? dakanji123 97 — 7y
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 — 7y
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 — 7y
View all comments (4 more)
0
Please teach me how lerp works. Show me examples dakanji123 97 — 7y
0
In Gui.BackgroundColor3 = original:lerp(goal,i). Why is " i " there? dakanji123 97 — 7y
0
Can you explain to me how that script works? dakanji123 97 — 7y
Ad

Answer this question