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

Ending A Loop but then restarting at while true?

Asked by 4 years ago
local seconds = game:GetService("ReplicatedStorage").CrashGoing.Seconds
local running = game:GetService("ReplicatedStorage").CrashGoing.Running
local gui = script.Parent.CrashSystem.SurfaceGui.TextBox
local number1 = script.Parent.Number1 --decimal
local number2 = script.Parent.Number2 --whole

function changingColor()
    while true do
        wait()
    if running.Value == true then
            wait(0.1)
            if number2.Value == 2 then
                if seconds.Value <=1 then
                    return end
                gui.TextColor3 = Color3.new(0, 0.333333, 1)
            end
            if number2.Value == 4 then
                if seconds.Value <=1 then
                    return end
                gui.TextColor3 = Color3.new(0, 1, 0.498039)
            end
            if number2.Value == 6 then
                if seconds.Value <=1 then
                    return end
                gui.TextColor3 = Color3.new(1, 0, 1)
            end
            if number2.Value == 10 then
                if seconds.Value <=1 then
                    return end
                gui.TextColor3 = Color3.new(1, 0.839216, 0.0235294)
            end
        end
    end
end

changingColor()

This works until the if seconds.Value comes along. Then the script just ends. I tried just using returns and what not however not worked. I want to make it so the script stops but then goes back to the while true do.

1 answer

Log in to vote
0
Answered by 4 years ago

You should not use return in a while loop, because putting return in a while loop would make it exit the loop. You can make it change the textcolor when the value of seconds is > 1, and ignore when the value of seconds <= 1.

function changingColor()
    while true do
        wait()
        if running.Value == true then
            wait(0.1)
            if number2.Value == 2 then
                if seconds.Value >1 then
                    gui.TextColor3 = Color3.new(0, 0.333333, 1)
                end
            end
            if number2.Value == 4 then
                if seconds.Value >1 then
                    gui.TextColor3 = Color3.new(0, 1, 0.498039)
                end
            end
            if number2.Value == 6 then
                if seconds.Value >1 then
                    gui.TextColor3 = Color3.new(1, 0, 1)
                end
            end
            if number2.Value == 10 then
                if seconds.Value >1 then
                    gui.TextColor3 = Color3.new(1, 0.839216, 0.0235294)
                end
            end
        end
    end
end

changingColor()
Ad

Answer this question