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

Game time/day time script loading night at day?

Asked by 3 years ago

i am making an game that requires day time. daytime as in a script that does a moon/sun cycling system. the thing is when the sun is supposed go up the moon does instead.

My code:

local mins = 60/1000

for i = 1, math.huge do
    game.Lighting:SetMinutesAfterMidnight(i)
    wait(60)
end

no errors nothing just loads the time wrong

1 answer

Log in to vote
1
Answered by 3 years ago

I might've interpreted this wrong, but I'm assuming you want a day/night cycle script.

Here's what I would do:

minutesAfterMidnight = 12 * 60 --Change the 12 to the starting time
while true do
    minutesAfterMidnight = minutesAfterMidnight + 0.15 --Change it to how much you want the sun or moon to shift each cycle
    game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight)
    wait(.05) --Change it to how quickly you want each cycle to go
end

The script itself is simple, but here's a basic breakdown:

The initial minutesAfterMidnight variable defines the starting time. The 12 is the hour and it multiplies it by 60 to get the minute.

It then loops it though, adding 0.15 minutes for every 0.05 seconds that passes in real life. You can play around with those values to get the desired rate. I wouldn't recommend changing the 0.15 value too high as it makes the sun/moon's movement really choppy and weird.

Hope this helps :)

0
And to your code above, I didn't really get what you're trying to do with the "mins" variable, so I don't really know how to correct it. You never specified an increment either. Plus, it seems like you want it to go on forever, so it's better to use "while true do". If you don't want it to repeat forever, you can always pause or stop it by changing the "true" to something else. Bob4koolest 78 — 3y
0
Thankyou @Bob4koolest Retallack445 75 — 3y
0
yep, np Bob4koolest 78 — 3y
Ad

Answer this question