I’ve looked everywhere for an answer to this but couldn’t find anything.
I know you can just make a 12am-6am system using plain wait()s but theres gotta be a better way to do it. Help would be greatly appreciated.
Edit: Looks like some people didn’t understand what I meant. I want to have a GUI go from 12am to 6am, not the actual time. Not sure how exactly I should do this, but here was one of my attempts.
-- i dont feel like writing the countdown but basically I just had a countdown for 270
local times = {
TwelveAM = 250,
OneAM = 220,
TwoAM = 190,
-- etc}
countdown.Changed:Connect(function()
if table.find(times, countdown.value) then
-- do whatever
end
end)
while true do
local TimeInUnix = os.time()
local Date = script.Parent
local stringToFormat = "%I:%M %p"
local result = os.date(stringToFormat, TimeInUnix)
Date.Text = result
wait(1)
end
local Gui = script.Parent
function getLightingTime()
local totalMinutes = game.Lighting:GetMinutesAfterMidnight()
local hours = math.floor(totalMinutes / 60)
local minutes = math.floor(totalMinutes % 60)
local period
if hours < 12 then
period = "AM"
else
period = "PM"
hours -= 12
end
if hours == 0 then
hours = 12
end
return string.format("%02d:%02d %s", hours, minutes, period)
end
while task.wait() do
Gui.Text = getLightingTime()
end
Daylight Cycle Script Parented to Workspace:
local dayLength = 45 --// In minutes — feel free to change this.
local cycleTime = dayLength*60
local minutesInADay = 24*60
local lighting = game:GetService("Lighting")
local startTime = tick() - (lighting:getMinutesAfterMidnight() / minutesInADay)*cycleTime
local endTime = startTime + cycleTime
local timeRatio = minutesInADay / cycleTime
if dayLength == 0 then
dayLength = 1
end
repeat
local currentTime = tick()
if currentTime > endTime then
startTime = endTime
endTime = startTime + cycleTime
end
lighting:setMinutesAfterMidnight((currentTime - startTime)*timeRatio)
task.wait(1/15)
until false
I did not create these scripts, these are some I had laying around that I picked up from the DevForum.
In your second Script, you have a startTime, but it uses tick(), but let me tell you that tick is the time in seconds since 1 January 1970, so can you explain what you did in that line? Because for me, it’s too confusing.
But I don’t get like why are you subtracting the no. of seconds from the tick()? Like tick() is a huge no. so subtracting from it doesn’t make any sense to me atleast. That’s why I asked for a clear explaination so I learn about what you did.
I do not know where I got it from, just that it is off of devforum
I literally know exactly what the script does, you have web developer in your title so im assuming you know little to nothing about specific roblox coding, i told you what it does
Hmm, if you are really 2 years experienced, then you should have known that what exactly tick() is. And it will be really good for “beginners” like me if you explain that specific line of code. Like what you did exactly there. See I’m not here to fight but to learn.