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

Making a script that mirrors real life time?

I'm trying to make a script that mirrors real life time, the script isn't working, I was wondering if anyone could help.

Here is the script:

while wait() do
	game.Lighting.TimeOfDay = os.time()
end

Notes: The script is a local script inside the Workspace.

1 comment

0

You didn't specify the problem.

2 answers

✓ Accepted answer

Lighting.TimeOfDay returns a string value (would look something like "12:00:00"), and os.time() returns an integer of "... how many seconds have elapsed since the UNIX epoch (1 January 1970, 00:00:00), under UTC time."

So, instead, I would suggest using Lighting.ClockTime (returns a numerical value in hours of current game time) and os.date() (click the link)

Your script could look something like:

while wait() do
    game.Lighting.ClockTime = os.date("*t").hour
end

Note: The above code would set the time according to the player's local time.

2 comments

0

Thanks!

0

Np

What I would do is make it link also to minutes and seconds:

while wait() do
	local seconds = os.date("*t")["sec"]
	local minutes = os.date("*t")["min"]
	local hours = os.date("*t")["hour"]
	
	if tonumber(seconds) <= 9 then
		seconds = "0"..seconds
	end
	
	if tonumber(minutes) <= 9 then
		 minutes = "0"..minutes
	end
	
	if tonumber(hours) <= 9 then
		hours = "0"..hours
	end
	
	game.Lighting.TimeOfDay = hours..":"..minutes..":"..seconds
end

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