I'm trying to make a door that opens at a certain time but my code won't work. I've gotten it to work a couple of times but it'll just open once and close once and not loop. Any help is appreciated.
minutesAfterMidnight = 0 while true do minutesAfterMidnight = minutesAfterMidnight + 60 game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight) wait(.1) end while true do if minutesAfterMidnight == 360 then script.Parent.Transparency = 1 script.Parent.CanCollide = false elseif minutesAfterMidnight == 720 then script.Parent.Transparency = 0 script.Parent.CanCollide = true wait(.1) end end
It isn't working because you have 2 while true do
loops. The first one never exits/breaks, so the second one never gets to start. Instead, combine them:
minutesAfterMidnight = 0 while true do minutesAfterMidnight = (minutesAfterMidnight + 60) % 1440 game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight) if minutesAfterMidnight == 360 then script.Parent.Transparency = 1 script.Parent.CanCollide = false elseif minutesAfterMidnight == 720 then script.Parent.Transparency = 0 script.Parent.CanCollide = true end wait(.1) end
The (minutesAfterMidnight + 60) % 1440
means that once minutesAfterMidnight is about to become 1440, it's automatically changed to 0 (since % 1440
means "the remainder after dividing by 1440"), allowing your door to open/close every day rather than just the first day.