Small issue with detecting night

Hi so I’m not a scripter at all, so I decided to follow a tutorial about street lamps (by ROBLOX).

The time is set 24h (midnight) in game, lamps are on. Whenever I do :time 14, they turn off.
And after trying to put it back to 24, they don’t turn on.
I have tried re scripting this, but I couldn’t find a solution to fix this.

local lightPart = script.Parent
local PointLight = lightPart.PointLight

while true do
 wait(0.1)
 if game.Lighting:GetMinutesAfterMidnight() > 6 * 60 then
  lightPart.Material = Enum.Material.Plastic
  PointLight.Enabled = false
  
 end
 if game.Lighting:GetMinutesAfterMidnight() > 18 * 60 then
  lightPart.Material = Enum.Material.Neon
  PointLight.Enabled = true
 end
end

Hopefully someone answers :slight_smile:

Pretty sure the lighting starts at 0 and goes to 23, so you’d have to also check if it is less than or equal to 6.

As I mentioned, I am not a scripter, so tell me how would you do that?

Try this:

local lighting = game:GetService("Lighting");
local lightPart = script.Parent;
local pointLight = lightPart.PointLight;

lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
	local ct = lighting.ClockTime;
	if (ct <= 6 or ct >= 18) then
		lightPart.Material = Enum.Material.Neon;
  		pointLight.Enabled = true;
	else
		lightPart.Material = Enum.Material.Plastic;
  		pointLight.Enabled = false;
	end
end)
4 Likes