What did I do wrong here? Opening doors at a certain time and closing at a certain time

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want the doors to be open at a certain time and I want the doors to be closed at a certain time. (Read script below)

  2. What is the issue? Include screenshots / videos if possible!
    The doors are open no matter what the ClockTime is.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    There are no solutions I have found.

Sorry for the kinda long script

local DoorOpened = false --Debounce

while wait() do
	if game.Lighting.ClockTime >= 12 and DoorOpened == false then
		DoorOpened = true 
		game.Workspace.DoorR2.Transparency = 0.5
		game.Workspace.DoorR2H.Transparency = 0
		game.Workspace.DoorL2.Transparency = 0.5
		game.Workspace.DoorL2H.Transparency = 0

		game.Workspace.DoorR2.CanCollide = true
		game.Workspace.DoorR2H.CanCollide = true
		game.Workspace.DoorL2.CanCollide = true
		game.Workspace.DoorL2H.CanCollide = true

		game.Workspace.DoorR1.Transparency = 1
		game.Workspace.DoorR1H.Transparency = 1
		game.Workspace.DoorL1.Transparency = 1
		game.Workspace.DoorL1H.Transparency = 1

		game.Workspace.DoorR1.CanCollide = false
		game.Workspace.DoorR1H.CanCollide = false
		game.Workspace.DoorL1.CanCollide = false
		game.Workspace.DoorL1H.CanCollide = false
		
	elseif game.Lighting.ClockTime <= 12 and DoorOpened == true then
		DoorOpened = false
		game.Workspace.DoorR2.Transparency = 1
		game.Workspace.DoorR2H.Transparency = 1
		game.Workspace.DoorL2.Transparency = 1
		game.Workspace.DoorL2H.Transparency = 1

		game.Workspace.DoorR2.CanCollide = false
		game.Workspace.DoorR2H.CanCollide = false
		game.Workspace.DoorL2.CanCollide = false
		game.Workspace.DoorL2H.CanCollide = false

		game.Workspace.DoorR1.Transparency = 0.5
		game.Workspace.DoorR1H.Transparency = 0
		game.Workspace.DoorL1.Transparency = 0.5
		game.Workspace.DoorL1H.Transparency = 0

		game.Workspace.DoorR1.CanCollide = true
		game.Workspace.DoorR1H.CanCollide = true
		game.Workspace.DoorL1.CanCollide = true
		game.Workspace.DoorL1H.CanCollide = true

		
	end
end

Is the script a local script or server script, and how are you changing the time?
Are you changing the time locally or on the server?

It’s a normal script located in Workspace. The way I am changing time is by this LocalScript in StarterPlayerScripts:

local function getTime()
	local date = os.date("!*t") -- this creates a table with {year = 1998, month = 9, day = 16, yday = 259, wday = 4, hour = 23, min = 48, sec = 10, isdst = false}
	local zone = date.hour + -7
	return ("%02d:%02d:%02d"):format(((zone)), date.min,date.sec) -- gets the hour minutes and seconds within that table and formats it 
end

while wait(1) do 
	game:GetService("Lighting").TimeOfDay = getTime() 
end

Changing the time from a localscript doesn’t replicate to the server script.

Cont:
You need a server script to change the time.

It does change the time in lighting.

The changes are visible to the client yes but they do not replicate to the server for it to be read.

So all I need to do is change the LocalScript to a Script or is there more?

If you want the doors to open/close at the same time for everyone then yes make the time changing a server script.

If you do not care about that you can just make the door script a localscript.

I changed it to a server script and now the time doesn’t change.

Where is the server script located?

StarterPlayerScripts THIRTY 3O CHARS

The server script can’t run in there, move it into workspace then it should work.

It works but, will the time be the same for everyone and will the doors be closed the same time for everyone?

Yes since the time is being changed on the server everyone sees the doors open and close at the same time.

1 Like

Okay, thank you so much for the help!