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

Why's my Disco ImageLabel not working?

Asked by 7 years ago

So I'm making a gui disco thing that changes color of an ImageLabel object. This is how the explorer looks for me:

-StarterGui -Title... -...Black -ImageLabel -Script <-this script

And this is the script:

local colors = {Color3.new(255,0,0),Color3.new(0,255,0),Color3.new(0,0,255)}

function change_color(new)
    local old = script.Parent.ImageColor3
    local dir = {
        r = 0,
        g = 0,
        b = 0   }

    if new.r < old.r*255 then
        dir.r = -1
    elseif new.r > old.r*255 then
        dir.r = 1
    else
        dir.r = 0
    end

    if new.g < old.g*255 then
        dir.g = -1
    elseif new.g > old.g*255 then
        dir.g = 1
    else
        dir.g = 0
    end

    if new.b < old.b*255 then
        dir.b = -1
    elseif new.b > old.b*255 then
        dir.b = 1
    else
        dir.b = 0
    end

    if new.r ~= old.r*255 then
    for r=old.r*255,new.r,dir.r do
        script.Parent.ImageColor3 = Color3.new(r/255,script.Parent.ImageColor3.g,script.Parent.ImageColor3.g)
        wait(0.01)
    end
    end

    if new.g ~= old.g*255 then
    for g=old.g*255,new.g,dir.g do
        script.Parent.ImageColor3 = Color3.new(script.Parent.ImageColor3.r,g/255,script.Parent.ImageColor3.b)
        wait(0.01)
    end
    end

    if new.b ~= old.b*255 then  
    for b=old.b*255,new.b,dir.b do
        script.Parent.ImageColor3 = Color3.new(script.Parent.ImageColor3.r,script.Parent.ImageColor3.g,b/255)
        wait(0.01)
    end
    end
end

while wait(0.2) do
    local color = colors[math.random(1,#colors)]
    print(color)
    change_color(color)
    math.randomseed(tick())
end

So it works otherwise properly, but it somewhy "teleports" the colors always when it changes the color from one to another. If you'd spot the problem and help me, I would really appreciate it,

thanks,

SwaggyDuckie

Answer this question