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

how do i make it so all the lights turn off/on at a certain time?

minutesAfterMidnight = 0
setLights = function()
	for i,v in next, workspace:GetChildren() do
		if v:IsA("SpotLight") then
			v.Enabled = true
		end
	end
end

while true do
	minutesAfterMidnight = minutesAfterMidnight + 10
	game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight)
 	wait(.1)
	if game.Lighting.TimeOfDay == "06:00:00" then
		setLights(false)
		end
	if game.Lighting.TimeOfDay == "18:00:00" then
		setLights(true)
	end
end

wat i have collected from others so far and edited..i have no idea how this works please explain//it is currently not working

1 answer

You're not taking an argument in your setLights function. Change it to this and maybe it will work.

function SetLightsEnabled(bool)
	local function GetAllLights(p)
		local lights = {}
		for _,v in next, p:GetChildren() do
			if v:IsA("Light") then
				table.insert(lights, v)
			end
			GetAllLights(v)
		end
	end
	for _,light in next, GetAllLights(workspace) do
		light.Enabled = bool
	end
end

2 comments

0

where exactly do i put tihs in the script?

0

You replace the "setLights = function() ... end" with that. Also remember to mark this as the answer to your question and give rep.

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