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

Why won't this code change the color of the GUI?

Asked by
thePyxi 179
8 years ago

This code is in a Script which is inside a Frame. It runs through the code perfectly, yet it won't show the changes when I test it.

Here is the code:

local obj = script.Parent
obj.BackgroundColor3 = Color3.new(0, 0, 0)
number = 0

while true do
    print("Looping...")
    color1 = Color3.new(0,29/255,36/255)
    wait(0.3)
    color1 = Color3.new(0,28/255,35/255)
    wait(0.3)
    color1 = Color3.new(0,27/255,34/255)
    wait(0.3)
    color1 = Color3.new(0,26/255,33/255)
    wait(0.3)
    color1 = Color3.new(0,25/255,32/255)
    wait(0.3)
    color1 = Color3.new(0,24/255,31/255)
    wait(0.3)
    color1 = Color3.new(0,23/255,30/255)
    wait(0.3)
    color1 = Color3.new(0,22/255,29/255)
    wait(0.3)
    color1 = Color3.new(0,21/255,28/255)
    wait(0.3)
    color1 = Color3.new(0,20/255,27/255)
    wait(0.3)
    color1 = Color3.new(0,19/255,26/255)
    wait(0.3)
    color1 = Color3.new(0,18/255,25/255)
    wait(0.3)
    color1 = Color3.new(0,17/255,24/255)
    wait(0.3)
    color1 = Color3.new(0,16/255,23/255)
    wait(0.3)
    color1 = Color3.new(0,15/255,22/255)
    wait(0.3)
    color1 = Color3.new(0,14/255,21/255)
    wait(0.3)
    color1 = Color3.new(0,13/255,20/255)
    print("Waiting...")
    wait(4)
    print("Continued.")
    color1 = Color3.new(0,14/255,21/255)
    wait(0.3)
    color1 = Color3.new(0,15/255,22/255)
    wait(0.3)
    color1 = Color3.new(0,16/255,23/255)
    wait(0.3)
    color1 = Color3.new(0,17/255,24/255)
    wait(0.3)
    color1 = Color3.new(0,18/255,25/255)
    wait(0.3)
    color1 = Color3.new(0,19/255,26/255)
    wait(0.3)
    color1 = Color3.new(0,20/255,27/255)
    wait(0.3)
    color1 = Color3.new(0,21/255,28/255)
    wait(0.3)
    color1 = Color3.new(0,22/255,29/255)
    wait(0.3)
    color1 = Color3.new(0,23/255,30/255)
    wait(0.3)
    color1 = Color3.new(0,24/255,31/255)
    wait(0.3)
    color1 = Color3.new(0,25/255,32/255)
    wait(0.3)
    color1 = Color3.new(0,26/255,33/255)
    wait(0.3)
    color1 = Color3.new(0,27/255,34/255)
    wait(0.3)
    color1 = Color3.new(0,28/255,35/255)
    wait(0.3)
    color1 = Color3.new(0,29/255,36/255)
    wait(4)
    number = number+1
    print(" Completed Cycle #"..number)
end

2 answers

Log in to vote
1
Answered by 8 years ago

When you set variables to properties it sets the variable to what that property is equal to.

So if I do

local position = game.Workspace.Part.Position

Position is a variable, it doesn't point to the Position of Part, it's set to what the Position of part was at the time

You have to set a variable to the object not the property

local obj = script.Parent
obj.BackgroundColor3 = Color3.new(0, 0, 0)
Ad
Log in to vote
0
Answered by 8 years ago

When you define color1, you set it as the background color.

When you change color1, you only change color1, as it's just a variable.

You need to change the background color, like so: script.Parent.BackgroundColor3 = Color3.new(0,29/255,36/255)

Also I recommend doing it like this since it's much cleaner looking:

function c3(r,g,b)
    return Color3.new(r/255, g/255, b/255)
end

local color = c3(0, 29, 36)

repeat
    wait(0.3)
    color = c3(0, color.g - 1, color.b - 1)
    script.Parent.BackgroundColor3 = color
until color == c3(0, 13, 20)
wait(4)
repeat
    wait(0.3)
    color = c3(0, color.g + 1, color.b + 1)
    script.Parent.BackgroundColor3 = color
until color == c3(0, 29, 36)
0
When I used this code, it instantly made the background black and nothing was happening. thePyxi 179 — 8y

Answer this question