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

how to make a smooth color cycling gui?

Asked by 5 years ago
Edited 5 years ago

i want to make a smooth color transitioning gui that goes through just about every color, this is my script I made that doesn't work.

parent = script.Parent


while true do
    for i = 1, 255 + .1 do
                   wait(.1)
        for x = 1, 255 +.1 do
                   wait(.1)
            for e = 255,1 -.1 do
parent.TextColor3 = Color3.new(i,x,e)
        wait(0.1)
        end
    end

    end
end
0
Why are you ending the last two loops and then using their variables? little1gaming 0 — 5y
0
Presumably you're trying to use the for loop's increment parameter? Use a comma instead of a plus => for i = 1, 255, .2 do...end. Also, Color3.new parameters are actually numbers from 0 to 1, so in your code, you'd be better suited using Color3.new(i/255, x/255, e/255). saenae 318 — 5y

1 answer

Log in to vote
1
Answered by
chomboghai 2044 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

I would use TweenService to do this.

You are creating three loops within each other, each cycling from 1 to 255. There are a few problems I want to point out with this.

Firstly, you are incorrectly using the for loop syntax. The correct syntax is:

for i = 1, 255, 0.1, do but you said for i = 1, 255 + 0.1 do. There are three parameters, the first being the initial number, the second being the final number and the third is the increment value. You are setting the second value to 255 + .1, so technically Lua is reading your for loop as

for i = 1, 255.1 do.

The second problem here is that you are looping all the loops within each other.

Essentially what you're cycling through is (0, 0, 0) -> (0, 0, 255) -> (0, 1, 0) -> (0, 1, 255) etc all the way to (255, 255, 255). Every step you wait(0.1), and each loop has 255 steps. This evaluates to a total waiting of 1,658,137.5 seconds or 19.194 days. I don't think you should be looping through every single possible colour that exists on the RGB scale, because it would take over 19 days for your text to fully cycle through all the colours.

Instead what I'd do is simply use the TweenService to cycle through the colours because you are able to tween Colour3 values.

local TweenService = game:GetService("TweenService")

local tweenInfo = TweenInfo.new(time, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut, -1, true, 0) -- these are my recommended settings, feel free to change

local tweenGoal = { -- what you want the final result to be 
    TextColor3 = Color3.new(1, 1, 1)
}

script.Parent.Color = Color3.new(0, 0, 0) -- Set the initial colour to black

tween = TweenService:Create(script.Parent, tweenInfo, tweenGoal)

tween:Play()

The above script will constantly change the text color from black to white, then back to black, and infinitely repeat itself.

TweenInfo api for editing the above script.

Although I haven't tested it, it might be that the color will change from black to white by flowing through the grays rather than the colors. If that's the case, then you can tween to a different color and play around until you find a color flow that works for you.

Hope this helps :)

Ad

Answer this question