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 = Whether or not a light is on/off?

So. What I am trying to do is if the time is in-between "17:00:00" and "04:00:00" (game time) then the lights are turned on, but what I am also trying to do is change the material of the light itself.

while wait() do
	if game.Lighting.TimeOfDay >= "17:00:00" and game.Lighting.TimeOfDay <= "06:00:00" then
		script.Parent.PointLight.Enabled = true
		script.Parent.Material = Enum.Material.Neon
	else
		script.Parent.PointLight.Enabled = false
		script.Parent.Material = Enum.Material.Plastic
	end
end

1 comment

0

Sorry, I tried to code on my phone. It didn't work very well as I couldn't test it. I got it the wrong way round and missed a ) on the end of the .Changed function. Hope this works for you!

1 answer

✓ Accepted answer

Using the built in function of Lighting, GetMinutesAfterMidnight(), you an find the minutes after midnight (as the function's name suggests...). You can then check it's between 360 (06:00:00 - found by using the example on the wiki page) and 1020 (17:00:00 - found by using the example on the wiki page). You may also want to use game.Lighting.Changed instead of a forever loop as it's more efficient. Your final code would be this:

function changeLight()
	local tam = game.Lighting:GetMinutesAfterMidnight()
	if tam <= 1020 and tam >= 360 then -- If it's between 06:00:00 and 17:00:00
		script.Parent.PointLight.Enabled = false
		script.Parent.Material = Enum.Material.Plastic
	else
		script.Parent.PointLight.Enabled = true
		script.Parent.Material = Enum.Material.Neon
	end
end

game.Lighting.Changed:connect(function()
	changeLight()
end)

changeLight() -- Run to get initial status

2 comments

0

Nope. :/

0

Sorry, I tried to code on my phone. It didn't work very well as I couldn't test it. I got it the wrong way round and missed a ) on the end of the .Changed function. Hope this works for you!

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