Hey developers,
I want to make an in-game clock system with game hours being real time minutes. I want the sun and moon to always be in the correct position throughout the day matching with the clock. How would I go about doing this?
Hmm well did you try assigning the local script in the Gui as:
local Time = game.Lighting
Time.Time.Changed:Connect(function()
Gui.Text = Time.Time
end)
I don’t think the property for time in lighting is called “time” but you get it right?
I believe you should have the clock correspond to the day/night cycle rather than the other way around. Not only does it make more sense but it’s just easier to do. I assume you have your daylight cycling script in the game already.
For the clock, let’s say it’s a TextLabel GUI on the screen. All we have to do here is put a LocalScript inside the TextLabel and enter this:
local Watch = script.Parent
local LightingService = game:GetService("Lighting")
LightingService:GetPropertyChangedSignal("ClockTime"):Connect(
function()
Watch.Text = LightingService.TimeOfDay
end
)
TimeOfDay is a property of game.Lighting that formats the in-game time according to the sun, and is easily readable to us.
4 Likes