I need help making Night cycle light script

I’m trying to make a Night cycle script that changes parts properties if timeclock is beginning to turn night. This will be useful for Street lights, or giving life to buildings in the city at night.

Example:

I’ve tried to do the same thing using the basic night cycle script on youtube using a local script however, my script isnt working. The part does change its property to neon material at night but, not to the color i’m telling it. It stays at an institutional white instead of yellow
https://gyazo.com/96eba1f5829c451a331e2fd9e4d82314

I’m very new to scripting and i’m trying to attempt to change an individual parts color in hopes of being able to duplicate the part and change the color for different buildings and assets, but this is very confusing, my output isnt telling me that the script is breaking or anything, Help!!!

3 Likes

In order for us to help you, you need to show your current code

I’d say instead of changing the lights and time of day with one script for each part (If you want) have a script that checks time of day and edits the accordingly and this script is just an example of what i would do

local NightStart == 00:00:00 -- Change this to when night to start
local NightEnd = 00:00:00 -- Change this to when night would end
local DayStart == 00:00:00 -- Change this to when day to start
local DayEnd = 00:00:00 -- Change this to when day would end
while true do
if game.Lighting.TimeOfDay <= NightStart and game.Lighting.TimeOfDay <= NightEnd then
script.Parent.Material = Enum.MaterialType.Neon -- This may be wrong as im typing this on the dev forum not studio
script.Parent.BrickColor = BrickColor.new("New Yeller") -- This may be wrong as im typing this on the dev forum not studio
elseif game.Lighting.TimeOfDay <= DayStart and game.Lighting.TimeOfDay <= DayEnd then
script.Parent.Material = Enum.MaterialType.SmoothPlastic -- This may be wrong as im typing this on the dev forum not studio
script.Parent.BrickColor = BrickColor.new("Medium stone grey") -- This may be wrong as im typing this on the dev forum not studio
end
wait(1) -- Change this to the time you want to loop to wait before repeating
end

Remember that was an example of what i would do although you can copy it is you wish. Also if you do copy you might want to fix any errors in typing and change the brick colors till you get a color you like and like @Wizard101fire90 if we are going to help you with YOUR code you need to show it

2 Likes

I fixed the errors

local NightStart == 17:58:11
local NightEnd = 05:30:00
local DayStart == 06:00:00
local DayEnd = 17:47:59
while true do
if game.Lighting.TimeOfDay <= NightStart and game.Lighting.TimeOfDay <= NightEnd then
script.Parent.Material = Enum.Material.Neon
script.Parent.BrickColor = BrickColor.new(“New Yeller”)
elseif game.Lighting.TimeOfDay <= DayStart and game.Lighting.TimeOfDay <= DayEnd then
script.Parent.Material = Enum.Material.SmoothPlastic
script.Parent.BrickColor = BrickColor.new(“Medium stone grey”)
end
wait
end

However it doesn’t do anything to the part im trying of which properties im trying to change due to the time of day :frowning:
On the left is the previous script and on the right is the script you’ve typed up
https://gyazo.com/f13c7ac76b835c6fef10d74f9c556683

By the way this was the previous script i was using
local lightPart = script.Parent

while true do
wait(0.1)
if game.Lighting:GetMinutesAfterMidnight() > 6 * 60 then
lightPart.Material = Enum.Material.Glass
lightPart.BrickColor = BrickColor.new (175, 221, 255)
lightPart.Reflectance = 0.65
end
if game.Lighting:GetMinutesAfterMidnight() > 18 * 60 then
script.Parent.BrickColor = BrickColor.new (204, 142, 105)
lightPart.Material = Enum.Material.Neon
lightPart.Reflectance = 0
end
end

WHICH works but doesn’t change to the color i want instead its institutional white

2 Likes

It has been over 3 years since this was posted, but I ran into this post while trying to figure the answer out myself. I got it to work using the following code:

while true do
	wait(0.1)
	if game.Lighting:GetMinutesAfterMidnight() > 6 * 60 then
		script.Parent.Material = Enum.Material.Glass
		script.Parent.Color = Color3.fromRGB(175, 221, 255) 
		script.Parent.Reflectance = 0.65
	end
	if game.Lighting:GetMinutesAfterMidnight() > 18 * 60 then
		script.Parent.Color = Color3.fromRGB(204, 142, 105)
		script.Parent.Material = Enum.Material.Neon
		script.Parent.Reflectance = 0
	end
end