#While loop stops running

1 messages · Page 1 of 1 (latest)

severe scroll
#

I'm currently working on a day night cycle, and have gotten a little stuck on this one problem I've encountered. What i'm currently trying to do is change a certain value to reflect the current time of day, which is represented by Lighting.ClockTime. The issue i've encountered is that the loop checking for the current ClockTime stops running after another value, which is responsible for pausing the movement of ClockTime, is changed. Below will be the current local script, any and all help on this topic will be appreciated <3

craggy wolf
craggy wolf
hidden gullBOT
#

studio** You are now Level 1! **studio

craggy wolf
#

Try combine up also some tween there, so it does make everything smooth

#

Cause this, might be useless.

    task.wait(1)
    if (Lighting.ClockTime >= 6 and Lighting.ClockTime < 6.5) then
        globalVariables.currentTime = 1
        currentTimeofDay.Value = globalVariables.timesofDay[globalVariables.currentTime]
        print(globalVariables.timesofDay[globalVariables.currentTime])
    elseif (Lighting.ClockTime >= 6.5 and Lighting.ClockTime < 7) then
        globalVariables.currentTime = 2
        currentTimeofDay.Value = globalVariables.timesofDay[globalVariables.currentTime]
        print(globalVariables.timesofDay[globalVariables.currentTime])
    elseif (Lighting.ClockTime >= 12 and Lighting.ClockTime < 12.5) then
        globalVariables.currentTime = 3
        currentTimeofDay.Value = globalVariables.timesofDay[globalVariables.currentTime]
        print(globalVariables.timesofDay[globalVariables.currentTime])
    elseif (Lighting.ClockTime >= 17 and Lighting.ClockTime < 17.5) then
        globalVariables.currentTime = 4
        currentTimeofDay.Value = globalVariables.timesofDay[globalVariables.currentTime]
        print(globalVariables.timesofDay[globalVariables.currentTime])
    elseif (Lighting.ClockTime >= 17.5 and Lighting.ClockTime < 18) then
        globalVariables.currentTime = 5
        currentTimeofDay.Value = globalVariables.timesofDay[globalVariables.currentTime]
        print(globalVariables.timesofDay[globalVariables.currentTime])
    elseif (Lighting.ClockTime >= 18 and Lighting.ClockTime < 18.2) then
        globalVariables.currentTime = 6
        currentTimeofDay.Value = globalVariables.timesofDay[globalVariables.currentTime]
        print(globalVariables.timesofDay[globalVariables.currentTime])
    end
end```
severe scroll
#

Thanks for responding, but I actually just found a better(?) solution to this in the form of using RunService instead of the loop

craggy wolf
#

As it can cause lag to the server.

#

That's what i know.

#

But u can stick around with it for now.

severe scroll
#

I'll try to keep in mind to use it sparingly for the future to prevent lag xD

craggy wolf
#

Like an rotating part or smth..

severe scroll
#

makes sense

craggy wolf
#

So that's why i found you! And wanted to give out an hand

craggy wolf
severe scroll
#

Disconnect does what it says, it disconnects the run service when you call it

#

So if you have like a heartbeat that you dont want to run outside of certain circumstances, in a function you can call Disconnect() in order to stop it

#

but you'll have to reconnect the heartbeat somewhere again if you need to use it again further down the script

craggy wolf
craggy wolf
#

Anyways i won't stress u anymore lol!

#

Thx for adding me! :D