Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Game time/day time script loading night at day?

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

✓ Accepted answer

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 :)

3 comments

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.

0

Thankyou @Bob4koolest

0

yep, np

This discussion is preserved as it was. New answers, comments, and votes are closed.