Hey there! I am trying to make a basic door that opens and closes at appropriate times of day! At 7am it should open and at 10pm it should close. The code isn’t working and I don’t know why!
local door = script.Parent
while true do
if game.Lighting.ClockTime == 07:00:00 then
door.Transparency = 1
door.CanCollide = false
end
if game.Lighting.TimeOfDay == 10:00:00 then
door.Transparency = 0
door.CanCollide = true
end
wait()
end
local open = false
while true do
if game.Lighting.ClockTime >= 7 and open == false then
--door stuff
open = true
elseif game.Lighting.ClockTime >= 10 and open == true then
--door stuff
open = false
end
end
Try placing this in a script and put the script in the workspace,it should make the door invisible between 7 to 10 and closed otherwise.
This script might not work if you manually change the time
local Door = game.Workspace.Door
while true do
if game.Lighting.ClockTime >= 7 and game.Lighting.ClockTime <= 10 then
Door.Transparency = 1
Door.CanCollide = false
end
if game.Lighting.ClockTime >= 10 then
Door.Transparency = 0
Door.CanCollide = true
end
wait()
end
local door = script.Parent
game:GetService('Lighting'):GetPropertyChangedSignal('ClockTime'):Connect(function()
local CurrentTime = game.Lighting.ClockTime
if CurrentTime == 7 then
door.Transparency = 1
door.CanCollide = false
elseif CurrentTime == 10 then
door.Transparency = 0
door.CanCollide = true
end
end)
This will work much better than constantly running a while loop. The “GetPropertyChangedSignal” only fires when the ClockTime value is changed from its current value.
That won’t have that much of a difference as from what he said, he is planning on using a Day/Night Cycle script which would result in the event firing constantly and not making any difference.