I need to change this blocks appearance in between 18:00 (6:00 PM) and 6:00 AM. I have the the entire script already there practically.
b = script.Parent
local oh,om = 6,00 -- Open Time (hours,minutes)
local ch,cm = 18,00 -- Close Time (hours, minutes)
local l = game:service("Lighting")
if (om == nil) then om = 0 end
if (cm == nil) then cm = 0 end
function TimeChanged()
local ot = (oh + (om/60)) * 60
local ct = (ch + (cm/60)) * 60
if (ot < ct) then
if (l:GetMinutesAfterMidnight() >= ot) and (l:GetMinutesAfterMidnight() <= ct) then
b.Material = "Plastic"
b.BrickColor = BrickColor.new("Black")
b.Transparency = 0
else
b.Material = "Neon"
b.BrickColor = BrickColor.new("Gold")
b.Transparency = 0.55
end
elseif (ot > ct) then
if (l:GetMinutesAfterMidnight() >= ot) or (l:GetMinutesAfterMidnight() <= ct) then
b.Material = "Plastic"
b.BrickColor = BrickColor.new("Black")
b.Transparency = 0
else
b.Material = "Neon"
b.BrickColor = BrickColor.new("Gold")
b.Transparency = 0.55
end
end
end
TimeChanged()
game.Lighting.Changed:connect(function(property)
if (property == "TimeOfDay") then
TimeChanged()
end
end)
Day/Night
-- dayLength defines how long, in minutes, a day in your game is. Feel free to alter it.
local dayLength = 12
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)
wait(1/15)
until false
Working Product
b = script.Parent
-- New Stuff!!
math.randomseed(tick()%1*1e7)
Thetime = math.random(180,190)
Thetime = Thetime/10
-- Converts Decimal to Minutes
Rounded = math.floor(Thetime)
Rounded = Thetime-Rounded
Rounded = Rounded * 60
Rounded = math.floor(Rounded)
Thetime = math.floor(Thetime)
-- Final Product
Hours = Thetime
Minutes = Rounded
print("Time has been selected for dark, Hours:" .. Hours .. " Minutes:" .. Minutes)
------------------------------------------------------------------------------------
-- New Stuff!!
math.randomseed(tick()%1*1e7)
Thetime2 = math.random(60,70)
Thetime2 = Thetime2/10
-- Converts Decimal to Minutes
Rounded2 = math.floor(Thetime2)
Rounded2 = Thetime2-Rounded2
Rounded2 = Rounded2 * 60
Rounded2 = math.floor(Rounded2)
Thetime2 = math.floor(Thetime2)
-- Final Product
Hours2 = Thetime2
Minutes2 = Rounded2
print("Time has been selected for dark, Hours:" .. Hours2 .. " Minutes:" .. Minutes2)
local l = game:service("Lighting")
function TimeChanged()
local Time = (Hours + (Minutes/60)) * 60
local Time2 = (Hours2 + (Minutes2/60)) * 60
if (Time>Time2) then
if(l:GetMinutesAfterMidnight() <= Time) and (l:GetMinutesAfterMidnight() >= Time2) then
b.Material = "Plastic"
b.BrickColor = BrickColor.new("Black")
b.Transparency = 0
else
b.Material = "Neon"
b.BrickColor = BrickColor.new("Gold")
b.Transparency = 0.55
end
elseif (Time<Time2) then
if (l:GetMinutesAfterMidnight() >= Time) or (l:GetMinutesAfterMidnight() <= Time2) then
b.Material = "Plastic"
b.BrickColor = BrickColor.new("Black")
b.Transparency = 0
else
b.Material = "Neon"
b.BrickColor = BrickColor.new("Gold")
b.Transparency = 0.55
end
end
end
TimeChanged()
game.Lighting.Changed:connect(function(property)
if (property == "TimeOfDay") then
TimeChanged()
end
end)

1 comment
K, i re-did my answer