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

Day/Night [closed]

Asked by 10 years ago

I feel really stupid D: Not the best with making scripts, but how do I create a basic day/night script?

0
Theres also day/night scripts in the catalog that work just fine you just put in how fast you want the cycle. RavenPixel 0 — 10y

Locked by Thewsomeguy and Articulating

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

4 answers

Log in to vote
4
Answered by 10 years ago

In many of my games, I use code similar to this to change the time of day at a rate 60 times as fast as real time:

while true do
        Game:GetService('Lighting'):SetMinutesAfterMidnight(Game:GetService('Lighting'):GetMinutesAfterMidnight() + wait())
end

The reason this is 60 times as fast as real time is because the wait function returns the time it waited in seconds, while GetMinutesAfterMidnight expects minutes. If you want the in-game time to correspond to real time, multiply the result of the call to wait by 60. You can multiply or divide it by other values to make it faster or slower.

This solution is optimal and better than previously described ones because it adds the result of the call to wait to the time. This means it takes into consideration the fluctuations in the time that is actually waited for. It therefore provides a more stable time cycle, while other the other solutions described add a certain amount of time to the game time every time wait returns, which can happen at varying periods of time.

Ad
Log in to vote
2
Answered by 10 years ago
l = game:service("Lighting")
while true do
    l:SetMinutesAfterMidnight(l:GetMinutesAfterMidnight()+.5)
    wait(.05)
end
Log in to vote
0
Answered by
MrNicNac 855 Moderation Voter
10 years ago

The easiest way to change the time mathematically is to use the :SetMinutesAfterMidnight() method of the lighting. The concept goes like this:

  • Get the minutes after midnight
  • Add a small amount to that number
  • Set the minutes after midnight to the new number
local lighting = Game.Lighting

while wait() do
    local newTime= lighting:GetMinutesAfterMidnight();
    lighting:SetMinutesAfterMidnight( newTime + .5 )
end
Log in to vote
0
Answered by
MunimR 125
10 years ago

Alright a basic way to create a day and night script is

while wait(1/2) do
    Game.Lighting:SetMinutesAfterMidnight(Game.Lighting:GetMinutesAfterMidnight()+1/5)
end

The way this works is that we have a while loop that runs every half a second. Then we use SetMinutesAfterMidnight based off GetMinutesAfterMidnight and after that we add a 1/5 of a minute.

(So to make this faster or slower change the looping time or the addition of minutes time)

curse you MrNicNac