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
#While loop stops running
1 messages · Page 1 of 1 (latest)
From what i see, ur trying to make an day/night cycle, that goes from day to night, and night to day. Using the clocktime prop. Am i right?
I do suggest you to make 2 functions, 1 being the day cycle, and 1 the night cycle. Try to use an global variable to detect when its night or day. And when the variable is set to night, to play the day cycle, then when is set to true for day, to start the night cycle.
** You are now Level 1! **
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```
Thanks for responding, but I actually just found a better(?) solution to this in the form of using RunService instead of the loop
Or yeah! You can use run service. But try to not use it as much!
As it can cause lag to the server.
That's what i know.
But u can stick around with it for now.
For this local script I'm only using it in two places so far
I'll try to keep in mind to use it sparingly for the future to prevent lag xD
Saw right now man! Yeah there is no issue! But i did told u cause so many ppl told me to not use runservice as much for small stuff
Like an rotating part or smth..
makes sense
Currently i do am an begginer at scripting haha! And trying my best to help others also in a good way!
So that's why i found you! And wanted to give out an hand
For me i am still trying to understand ":Disconnect()" on what it means and if its useful or not!
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
Oh! wait my bad! It was with something like: "connection or smth" with made an temp connection, and disconnected it in a exact matter of time.
And idk if that's like an variable which like: "Summon an boss, if the boss haves 0 health, then summont he connection, disconnect it, destroy it." Or idk loL!
If i want for example an random rotateing part, then its not needed haha! :). But yeah. Its pretty useful disconnect in runservice! but check up! ^^^
Anyways i won't stress u anymore lol!
Thx for adding me! :D