So I've been doing a bit of research on this type of matter. I've tried wiki, discord, youtube, google search, and this is pretty much my last option. I've searched up time gui on this website too, to see if anything would suit my situation, but each script didn't work- since it wasn't made for me. I want to make either a text label (preferred for me) or a text box to make the time change. I also want it to go along with the time of day. I know I could say something like:
script.Parent.Parent.Parent.Lighting.TimeOfDay = "24:00:00"
but I don't know how to go about this? Help please?
You can use string patterns!!!
TextLabel.Text = string.format("%d:d", math.floor(Lighting.ClockTime/60), Lighting.ClockTime%60)
The %d
format specifier specifies a digit, and %0 2 d
specifies at least 2 digits will be in the number. So if your number is 1 digit, it would look like 0n
where n
is between 0-9
.
You divide by 60 to get the hours (or minutes), and you mod by 60 so that it wraps around 60, you don't see clocks that say 7:60
or 3:81
.
The site keeps screwing with the pattern, the pattern is
Percent d colon percent zero two d
% d:% 0 2 d
Remove the spaces
Assuming you already know how to make the gui with a text button. The easiest path for finding the time of day would be:
game:GetService("Lighting").TimeOfDay
For changing it you could utilize clock time:
local time = game:GetService("Lighting").ClockTime --If you wanted to set it you could do something like this (Path to button).MouseButton1Click:Connect(function() time = x --Desired time here ranging from 0 to 23.99 end) --Or if you wanted to increment it bit by bit (Path to button).MouseButton1Click:Connect(function() time = time + x --However much you wanna increment the time by end)
Not entirely sure if this is the most efficient way of doing so but this is personally what I'd do. Something to note is that if you ever go above 23.99 or below 0, whether by setting the time or by adding to it, the game will default the clock time to 0.
As for the tracking of the time for say, something like a clock you could have a text label set up and have something like this:
game:GetService("Lighting").Changed:Connect(function() (path to text label).Text = game:GetService("Lighting").TimeOfDay end
Not sure if this is the answer you were looking for but hope it helps.