I made a script that should change the background color of my main menu but it doesnt work.
Does anyone know why, and how to fix it?
It's supposed to loop forever but it only changes it to red and then yellow and it stops.
local A = 250 local B = 0 local C = 0 while 1 + 1 == true do repeat script.Parent.BackgroundColor3 = (Color3.new(A, B, C)) B = B + 25 wait(0.2) until B == 250 repeat script.Parent.BackgroundColor3 = (Color3.new(A, B, C)) A = A - 25 wait(0.2) until A == 0 repeat script.Parent.BackgroundColor3 = (Color3.new(A, B, C)) C = C + 25 wait(0.2) until C == 250 repeat script.Parent.BackgroundColor3 = (Color3.new(A, B, C)) B = B - 25 wait(0.2) until B == 0 repeat script.Parent.BackgroundColor3 = (Color3.new(A, B, C)) A = A + 25 wait(0.2) until A == 250 end
Thank you for your time.
To address your problem, 1+1 does not equal true
, it equals 2
. There's no reason to have any other statement between your while loop
unless it's a function that yields
, or just putting the true
(boolean statement) directly in the condition for the while loop.
Here would be your alternative:
while true do -- ... ect -- Just make sure you have something that yields your thread, since we're making it an infinite loop. end
Or if you insist on using the condition you provided, here's how you'd write it:
while 1+1 do -- ect end
Or...
while 1+1==2 do -- ect end
Or...
while 1+1~=1 do -- ect end
This literally goes on forever. I'd just stick with using "true" as your while condition, as long as you throw a wait()
somewhere in there.
EDIT:
And as Pyrondon has stated, Color3 values only range from 0-1 (0 being black, and 1 being white). Which means you'd have to divide your numbers by 255, to get the decimal result.
Color3 values must be divided by 255 to work, as they have to be in between 0 and 1.
local A = 250 local B = 0 local C = 0 while 1 + 1 == true do repeat script.Parent.BackgroundColor3 = (Color3.new(A/255, B/255, C/255)) B = B + 25 wait(0.2) until B == 250 repeat script.Parent.BackgroundColor3 = (Color3.new(A/255, B/255, C/255)) A = A - 25 wait(0.2) until A == 0 repeat script.Parent.BackgroundColor3 = (Color3.new(A/255, B/255, C/255)) C = C + 25 wait(0.2) until C == 250 repeat script.Parent.BackgroundColor3 = (Color3.new(A/255, B/255, C/255)) B = B - 25 wait(0.2) until B == 0 repeat script.Parent.BackgroundColor3 = (Color3.new(A/255, B/255, C/255)) A = A + 25 wait(0.2) until A == 250 end
Hope this helped.