I'm trying to generate a bell system relying on a table.. I feel like there's an easier method of checking what time its on, and using it to check what period its on. So far, here is my results. Although it's going great and barely working, Is there a better way to prevent un-necessary server load? I'm all in trying my best to keep the server working on important tasks like keeping players lag free..
PSchedules={
{"TESTBLOCK",{
-- name time start time end
{"Period 1", 10,41, 10,43},
{"Period 2", 10,45, 10,46},
{"Period 3", 10,47, 10,49},
{"Period 4", 10,50, 10,51}
}}
}
require game.ServerScriptStorage.GetTime; --returns a function that gives back my current time in this format (return hour,min,sec,amORpm)
function StartBell(schedu)
local bellloop=true
local schn=tonumber(schedu)
if schn~=nil then
local hours,mins,secs,pm=GetTime()
local checkloop=1
local isonperiod=false
for a=1,#PSchedules[schn][2] do
print(hours,PSchedules[schn][2][a][2])
if hours>=PSchedules[schn][2][a][2] then
if mins>=PSchedules[schn][2][a][3] then
print("passd "..schn,a)
checkloop=a
end
end
end
if hours <= PSchedules[schn][2][checkloop][4] then
if mins < PSchedules[schn][2][checkloop][5] then
isonperiod=true
end
end
repeat
hours,mins,secs,pm=GetTime()
local remainmins=0
isonperiod=false
if hours <= PSchedules[schn][2][checkloop][4] then
if mins < PSchedules[schn][2][checkloop][5] then
if hours > PSchedules[schn][2][checkloop][2] then
if mins >= PSchedules[schn][2][checkloop][3] then
isonperiod=true
end
end
end
end
if isonperiod==true then
print("Is On Period..")
remainmins=0
if hours < PSchedules[schn][2][checkloop][4] then
remainmins=PSchedules[schn][2][checkloop][4]-hours
remainmins=remainmins*60
print("Added "..remainmins".. to remaining time..")
end
if PSchedules[schn][2][checkloop][5] > mins then
remainmins=remainmins+PSchedules[schn][2][checkloop][5]-mins
end
print("Remaining Time set to "..remainmins)
else
print("Is Not On Period..")
if PSchedules[schn][2][checkloop]==nil then
bellloop=false
print("The bell could NOT find the next loop and died..")
else
if PSchedules[schn][2][checkloop][2]==hours then
if PSchedules[schn][2][checkloop][3]<mins then
checkloop=checkloop+1
print("Added to next wait loop")
end
end
if PSchedules[schn][2][checkloop][2]==hours then
print("Waiting Till Next Period..")
remainmins=0
if hours < PSchedules[schn][2][checkloop][2] then
remainmins=PSchedules[schn][2][checkloop][2]-hours
remainmins=remainmins*60
end
if PSchedules[schn][2][checkloop][5] > mins then
remainmins=remainmins+PSchedules[schn][2][checkloop][3]-mins
end
end
end
end
print("CurrentTime: "..hours..":"..mins)
print("NextPeriodBeforeTime: "..PSchedules[schn][2][checkloop][2]..":"..PSchedules[schn][2][checkloop][3])
print("NextPeriodAfterTime: "..PSchedules[schn][2][checkloop][4]..":"..PSchedules[schn][2][checkloop][5])
print("RemainingMinutes: "..remainmins)
print("CurrentSchedule: "..PSchedules[schn][1])
print("CurrentPeriod: "..PSchedules[schn][2][checkloop][1])
print("Is it that period?: "..(isonperiod and "true" or "false"))
print("----------------------------------")
wait(2)
until bellloop==false
end
print("TheBellDied..")
bellloop=false
end
StartBell(1)
Am I going overboard on how to check for this information, or is their an easier way?

2 comments
Yeah, I'd say you went WAY OVERBOARD, but it is some interesting code. Is GetTime telling you a true time of the server, or a ficticious time within the game?
GetTime() is using os.time() that works on all game servers in one time zone.