How do I make a day and night cycle function on the server?

My problem may sound easy, but i’ve been stumped on it for soo long! I have no idea why, but nothing I seem to do works! I am trying to get the ClockTime under Lighting to change via a server script for a day and night cycle, but the script simply does nothing when the game is played, client or serversided. The only functional script i’ve gotten to work is making a local script and putting it in StarterPlayerScripts, but I want everyones time to be the same.

Here is my code:

while task.wait(0.1) do
	game.Lighting.ClockTime += 0.004

This is a server script and it is under Lighting, yet it still doesn’t work… Is this a ROBLOX bug, or a issue I made? Please help!!!

i think your script should work on the server

you could also use a more constant measure of time like unix to control the time on the client

while task.wait(1) do
  local unix = os.time() -- number of seconds past some day in 1990 or something
  game.Lighting.ClockTime = unix

Scripts with the RunContext set to Legacy won’t run in Lighting. Put it in ServerScriptService instead or set it’s RunContext to Server.

Thank you! I definitely need to touch up on what scripts work where and what RunContext to use, such a beginner mistake I made… Thank you anyways!

No problem!

RunContext should really only be used in cases where you want to organize server/client stuff in a single and/or organized container instead of separately, or you want the script to run in containers where it normally wouldn’t (like in this case).

Other than that, I would say just stick with the Legacy RunContext.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.