Roblox Event Playing Every Hour

Hello, I am trying to make a custom concert play every hour on the hour through a script.

I have tried to do this several times and looked online for countless of hours and still can not figure this out. I had a script I used to see if that worked but the event only played once and not again the next hour.

I have looked on Youtube, Devfourm, and roblox pages.

local launchEvent = workspace.RocketModel.Launch
local EventStart = 1615996980
local EventStop = 1615997040

local EventTime = workspace.EventText.TextPart.SurfaceGui.EventTime

while wait(1) do
local currentTime = os.time()

if currentTime >= EventStop then
    break
end

if currentTime >= EventStart then
    launchEvent:Fire()
    EventTime.Text = "Starting live event!"
    break
    
else
    local secondsleft = EventStart - currentTime
    local days = math.floor(secondsleft % (60*60*24*30) / (60*60*24))
    local hours = math.floor(secondsleft % (60*60*24) / (60*60))
    local minutes = math.floor(secondsleft % (60*60) / 60)
    local seconds = secondsleft % 60
    
    EventTime.Text = "Time till live-event: "..days.." Days "..hours.." Hours "..minutes.." Minutes "..seconds.." seconds!"
    
end

end
I have tried this script but the event playing every hour is still confusing to me on how to accomplish that.

2 Likes

The start time will expire as soon as that hour has passed, since unix doesn’t loop like that.
In order to check if an hour has passed, use this code.

local currentDate = os.date("!*t", os.time())
local nextHour = os.time({
	year = currentDate.year, month = currentDate.month, day = currentDate.day,
	hour = currentDate.hour + 1, min = currentDate.min, sec = currentDate.sec
})
local secondsUntilNextHour = nextHour - os.time()
local nextMinute = os.time({
	year = currentDate.year, month = currentDate.month, day = currentDate.day,
	hour = currentDate.hour, min = currentDate.min + 1, sec = currentDate.sec
})
local secondsUntilNextMinute = nextMinute - os.time()
local launchEvent = workspace.RocketModel.Launch

local EventStart = secondsUntilNextHour
local EventStop = secondsUntilNextMinute

local EventTime = workspace.EventText.TextPart.SurfaceGui.EventTime

while wait(1) do
local currentTime = os.time()

if currentTime >= EventStop then
    break
end

if currentTime >= EventStart then
    launchEvent:Fire()
    EventTime.Text = "Starting live event!"
    break
    
else
    local secondsleft = EventStart - currentTime
    local days = math.floor(secondsleft % (60*60*24*30) / (60*60*24))
    local hours = math.floor(secondsleft % (60*60*24) / (60*60))
    local minutes = math.floor(secondsleft % (60*60) / 60)
    local seconds = secondsleft % 60
    
    EventTime.Text = "Time till live-event: "..days.." Days "..hours.." Hours "..minutes.." Minutes "..seconds.." seconds!"
    
end

This is a bit complicated and can be solved a different way.

There are 3600 seconds in 1 hour. Using this information, you can add said number to EventStart each time you loop through and it’s the starting time.

Another reason why the OP is experiencing issues is because they call break on the loop, which terminates it indefinitely.

local LaunchEvent = game.Workspace.RocketModel.Launch

local EventStart = 00000000 -- Start of first event
local EventTime = game.Workspace.EventText.TextPart.SurfaceGui.EventTime

while task.wait(1) do
     local CurrentTime = os.time()

     if CurrentTime == EventStart then
          EventStart += 3600

          LaunchEvent:Fire()
          EventTime.Text = "Starting live event!"
     else
          local SecondsLeft = EventStart - CurrentTime
          
          local Hours = math.floor(SecondsLeft % (60 * 60 * 24) / (60 * 60))
          local Minutes = math.floor(SecondsLeft % (60 * 60) / 60)
          local Seconds = SecondsLeft % 60

          EventTime.Text = Hours.." hours and "..Seconds.." seconds until the live event!"
     end
end
3 Likes


That brings me to my next thing. It says 9 hours. I want it so it starts every hour. You are super helpful and I did what you said and for “EventStart” I put 1000. I’m not really sure what number to put for the EventStart to make it play every hour.

1 Like

Well, os.time() returns the unix epoch timestamp, which is every second that has passed since January 1, 1970.

Putting 1000 for the start will not work. I’d recommend using an online epoch converter.

Screenshot 2023-08-08 171254
I have also tried that and set it to my time and it now shows this, once it gets down to 23 hours and 0 seconds, it resets back at 23 hours and 59 seconds. Repeating that loop

That must be an issue with the math you had in the original script.

Okay, so I got it to play but then after that it doesn’t play the next hour. It sets a time for tmrw at the same time. So it won’t go an hour later but sets for tmrw instead so one event per day.