Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How would I go about making a time gui with text labels and boxes?

Asked by
s_iara 94
5 years ago
Edited by User#24403 5 years ago

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?

0
Posting a link or giving tips would be very appreciated too s_iara 94 — 5y
0
You do realise roblox provides a built in variable: game. Why go the long route script.Parent.Parent.Parent? Seriously User#24403 69 — 5y
0
^ I am aware of that and this was an example s_iara 94 — 5y
0
Ok but why did you do it? And you want to input a time of day in a text box, and the time of day equals that input? In that case: Lighting.TimeOfDay = TextBox.Text User#24403 69 — 5y
View all comments (2 more)
0
I would have done that, except, if it were supposed to be 2:47, it would say 14:47 and I don't want that s_iara 94 — 5y
0
Where would I put this bit into the script?     Lighting.TimeOfDay=TextLabel.Text...? s_iara 94 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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

0
So I put this script into my TextLabel and it would work? I already have a day and night script currently. s_iara 94 — 5y
0
Yes and you gotta modify it to work as itnisnt copy paste friendly, you need to define the variables User#24403 69 — 5y
0
Thank you so much! It works fine s_iara 94 — 5y
Ad
Log in to vote
1
Answered by 5 years ago

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.

0
It wasn't what I was looking for because I don't need a textbutton, but I do get the idea. Thanks for the help though, I appreciate it. s_iara 94 — 5y

Answer this question