So. I have a script in which when the time reaches 21:00:00, or 9pm, the scripts to open a gate stop working and then when the time reached 6:00:00 it re-activates.... BUT, it doesn't work, could someone help?
Current Code:
if game.Lighting.TimeOfDay == "21:00:00" then game.workspace.Security.Rear.Open.R.Enabled = false game.workspace.Security.Rear.Open.L.Enabled = false game.workspace.Security.Front.Open.R.Enabled = false game.workspace.Security.Front.Open.L.Enabled = false elseif game.Lighting.TimeOfDay == "06:00:00" then game.workspace.Security.Rear.Open.R.Enabled = true game.workspace.Security.Rear.Open.L.Enabled = true game.workspace.Security.Front.Open.R.Enabled = true game.workspace.Security.Front.Open.L.Enabled = true end
Layout: http://prntscr.com/904eu9
First off, your if statements are wrong. elseif
does not require its own end.
if condition then --code elseif condition2 then --code end
Second, Lighting
needs to be capital.
game.Lighting
Third, when doing comparisons, you need to use two equal signs:
if a == b then
Fourth, TimeOfDay
is actually a string, so check it like this:
if game.Lighting.TimeOfDay == "21:00:00" then
while true do wait() if game.lighting.TimeOfDay == 21:00:00 then game.workspace.Security.Rear.Open.R.Enabled = false game.workspace.Security.Rear.Open.L.Enabled = false game.workspace.Security.Front.Open.R.Enabled = false game.workspace.Security.Front.Open.L.Enabled = false
elseif game.lighting.TimeOfDay == 06:00:00 then game.workspace.Security.Rear.Open.R.Enabled = true game.workspace.Security.Rear.Open.L.Enabled = true game.workspace.Security.Front.Open.R.Enabled = true game.workspace.Security.Front.Open.L.Enabled = true end
end