Day/night cycle light not working

hey, so i’ve been trying to make a light that turns on and off according to the time of day and i’ve been having a bit of a hard time trying to figure out why its not turning on when its night time.

i’ve made it print night whenever its night time and etc to see if the entire script wasnt working or just the night time and its printing day but not night whenever it gets to it

i’m not sure if this is just because i followed an outdated tutorial or i wrote something wrong, i’ve checked the script in the tutorial and my script side by side and i dont really see a difference that can break the script.

local light = script.Parent
local point = light.PointLight

while true do
	wait(0.1)
	if game.Lighting:GetMinutesAfterMidnight() > 6 * 60 then
		print("Day")
		light.Material = Enum.Material.SmoothPlastic
		point.Enabled = false
	end

	if game.Lighting:GetMinutesAfterMidnight() > 18 * 60 then
		print("Night")
		light.Material = Enum.Material.Neon
		point.Enabled = true
	end
end
2 Likes

Hi this should work :+1:

local light = script.Parent
local point = light.PointLight

local MAM
while true do
	wait(0.1)
	MAM = game.Lighting:GetMinutesAfterMidnight()
	if (MAM >= 6 * 60 and MAM < 18 * 60) then
		print("It's DayTime")
		light.Material = Enum.Material.SmoothPlastic
		point.Enabled = false
	end

	if ((MAM >= 18 * 60 and MAM < 24 * 60) or (MAM >= 0 and MAM < 6 * 60)) then
		print("It's NightTime")
		light.Material = Enum.Material.Neon
		point.Enabled = true
	end
end

Also keep in mind if you try this in Studio Change the current Time server side :wink:

2 Likes

@AndyVT Is it solved ? :thinking:

No, its only reading it as day time for some reason :confused:

How and where are you changing the current lighting (clocktime, TimeOfDay, Etc…) LocalScript, ServerScript ?

im using server script to change the time im pretty sure and local for the light

I guess the LocalScript is in the part if so It can’t work you will need a Normal Script or you can put the LocalScript in the StarterPlayerScripts and change 1 Line

local light = game.Workspace.PartName


OR