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

Well I don't even know what happened! Color3, why do you do this to me?

Asked by
Maxomega3 106
10 years ago

32130, 49215, 20655

That is not a legitimate Color3 value, for those of you who don't know.

I'm writing a short script to make a color changing light, and I thought it was simple, but apparently isn't.

I wrote this very quickly, so I don't mind sharing it.

light = script.Parent;
r = math.random (0,255)
g = math.random (0,255)
b = math.random (0,255)
colors = {r,g,b}

function UpdateColor ()
    light.Color = Color3.new (r,g,b)
    wait (.1)
end

while wait () do
    for i,v in pairs (colors) do
        for i = 0,255 do
            if v < 255 then
                v = v + 5;
                UpdateColor ()
            else v = 0;
                UpdateColor ()
            end
        end
    end
end

As for the number at the top, that's what the Color3 value becomes after I enable the script. I cannot fix it. Thanks in advance! (Color3's could be a new tag)

2 answers

Log in to vote
1
Answered by
Ripull 45
10 years ago
    light.Color = Color3.new (r/255,g/255,b/255)

light = script.Parent;

function UpdateColor ()
r = math.random (0,255)
g = math.random (0,255)
b = math.random (0,255)
colors = {r,g,b}
    light.Color = Color3.new (r,g,b)
    wait (.1)
end

while wait () do
    for i,v in pairs (colors) do
        for i = 0,255 do
            if v < 255 then
                v = v + 5;
                UpdateColor ()
            else v = 0;
                UpdateColor ()
            end
        end
    end
end
0
I forgot that about Color3's. Thanks! Unfortunately, now it doesn't change colors. Maxomega3 106 — 10y
0
Because, you only run math.random once for each colour. Ripull 45 — 10y
0
light = script.Parent; function UpdateColor () r = math.random (0,255) g = math.random (0,255) b = math.random (0,255) colors = {r,g,b} light.Color = Color3.new (r,g,b) wait (.1) end while wait () do for i,v in pairs (colors) do for i = 0,255 do if v < 255 then v = v + 5; UpdateColor () else v = 0; Upda Ripull 45 — 10y
0
edited main post Ripull 45 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

Someone answered while I was typing, I can delete the answer if asked to

I was told in one of my previous questions that Color3 values range from 0 to 1 and not from 0 to 255. http://wiki.roblox.com/index.php/Color3

For this to work you would need to divide each value of Color3 by 255 eg:

light.Color = Color3.new (r/255,g/255,b/255)

also your for loop runs 3 times, inside that another for loop using the same variable (i) runs 256 times (consider changing i to something else). Every time it runs it will add 5 to the color (making it a
solid color again because rgb ranges from 0-1 so change this to 5/255), then showing that color (which will eventually turn white then black).

0
What I want it to do is to increase the amount of one color in the Color3 until it changes 255 times. Then, I want the same thing to happen to the next color. Will that not get the desired effect? For example: for every .1 seconds, red will increase by 1 for 255 times. Then, green will do the same thing. Next, blue. Maxomega3 106 — 10y
0
Yes, that is what happens, but say r gets randomized to 254 then it will only change color once (nearly white - white) then stays black for the remaining 254 repeats crackabottle123 110 — 10y
1
Huh? No, I don't think so. It should pick a number (say 42), and increase and increase until it gets back to 42. Then the next color will do the same thing. Not entire random. but close enough. Maxomega3 106 — 10y
0
Wow, really sorry about that, didn't read close enough you are 100% right. crackabottle123 110 — 10y
0
Haha, thanks. Unfortunately the color doesn't change. Interesting thing happened. I put in a print statement to print v, and that part works fine. Apparently v isn't connecting with any of the color levels. Maxomega3 106 — 10y

Answer this question