Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Time of day = Script Disables? [ANSWERED]

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?

So. I have 3 different codes which all don't work, making even 1 of them work would be a miracle

game.Lighting.LightingChanged:connect(function(TimeOfDay)
    if TimeOfDay 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
    else
    	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)


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
game.Lighting.TimeOfDay.Changed:connect(function()
	if game.Lighting.TimeOfDay == "21:00:00" then -- Night
    	game.Workspace.Security.Rear.Open.R.Disabled = true
    	game.Workspace.Security.Rear.Open.L.Disabled = true
    	game.Workspace.Security.Front.Open.R.Disabled = true
    	game.Workspace.Security.Front.Open.L.Disabled = true
	
	elseif game.Lighting.TimeOfDay == "6:00:00" then --Day
    	game.Workspace.Security.Rear.Open.R.Disabled = false
    	game.Workspace.Security.Rear.Open.L.Disabled = false
    	game.Workspace.Security.Front.Open.R.Disabled = false
    	game.Workspace.Security.Front.Open.L.Disabled = false
	end
end)
	

1 comment

0

its game.Lighting.Changed and i'ts that on 3rd scripr too

2 answers

✓ Accepted answer

Nvm, I just realized that you could just make it a loop to check for it all the time. Here you go:

while wait() do
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

3 comments

0

Yes, do you want a copy of what the script says?

0

Sure

2

Edited my answer, I'd really much appreciate an upvote, etc.

I bet you put this script in Lighting, put it somwhere like Workspace or ServerScriptService

This discussion is preserved as it was. New answers, comments, and votes are closed.