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

How to fade through color3 values?

Asked by
5_4h 8
4 years ago

I'm not sure how to loop through color3 values. I want it to fade from green all the way back to green. I've achieved this in the past, but once again forgot what to do.

This is what I tried.

for i = 1,255 do
something.BackgroundColor = Color3.new(0, i, 0)
end

I know that it just goes up from black to green, but I don't even know where to start for that.

1
You should check TweenService in Roblox API, it allows you to tween Color3 values. iDarkGames 483 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

I am not sure how you want this to function but you might be better off using HSV.

This is a quick example of HSV a loop in a frame.

local runServ = game:GetService('RunService')

local frame = script.Parent

while true do
    for i=0, 1, 0.001 do -- loop through hue range
        frame.BackgroundColor3 = Color3.fromHSV(i, 0.5, 0.5)
        runServ.RenderStepped:Wait()
    end
end

If you are looking for a differnt type of colour loop then you might be better off using the tween service or using the lerp function of the color3 roblox data type.

I hope this helps. please comment if you have any other questions.

0
I'll send a link of what I mean. This is my friend's channel and look at the background that has the fading colors. https://www.youtube.com/watch?v=-i_YHaVyofs 5_4h 8 — 4y
Ad
Log in to vote
-1
Answered by 4 years ago

I would suggest looking into the TweenService if you're going to do more complex fading later but as for your script the problem is that the Color3 value expects a value from 0 to 1, This is your script but fixed:

for i = 1,255 do
    something.BackgroundColor = Color3.new(0, i/255, 0)
end

Answer this question