Timed Door Not Working

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

Try using Lightning.ClockTime instead and use regular numbers,for example instead of 07:00:00 use 7

maybe its because 10:00:00 happens to fast the computer doesnt recognise it. Try an interval like 9:59:00 and 10:01:00

or maybe time of day is greater than this number?

Lighting.TimeOfDay is a string value. 07:00:00 and 10:00:00 should be strings like so:

if game.Lighting.TimeOfDay == "10:00:00" then

Edit: additionally, you mentioned it should close at 10pm. TimeOfDay represents 24 hour time, so 10 PM is 22:00:00.

I haven’t made a day/night script yet so that can’t be it. I’m manualy setting the time to see if it works

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

nope this didnt work for me :confused:

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.

idk why this one didnt work :thinking:

Are you changing the ClockTime or TimeOfDay property?

im testing with clock time by typing in for say “7” to see if the door opens or not

Do you have server selected when you’re changing the value? It’s client by default and any client-side changes won’t be replicated to the server.

This worked! Thanks everyone for helping!

No problem! :slight_smile: Glad to be able to help!