How to make Lighting script always detect whether or not

It detects what time it is, but when paired with a day/night script will not change.

is there something I don’t have in the script to make this work?

local Clocktime = game.Lighting.ClockTime

local LightPart = script.Parent


if Clocktime <= 17 then
	LightPart.BrickColor = BrickColor.new("Medium Stone Grey")
	LightPart.Material = ("SmoothPlastic")
end

if Clocktime >=18 then
	LightPart.BrickColor = BrickColor.new("Institutional White")
	LightPart.Material = ("Neon")
end


Is the script you shared with us a server script, and the day/night changer a LocalScript?

no, this is in a part, and should detect time and change the part’s color, but will not.

I mean like, what type of script is the Lightning and Day/Night? Is it a LocalScript, or a server script (a regular one)? Your code seems fine, as I tested it, so it might just depend on the type of script you are using for both of the scripts.

You would have to constantly run this code over and over again as the time changes. You could use a loop to accomplish this or RunService

game:GetService("RunService").Heartbeat:Connect(function()
	local Clocktime = game.Lighting.ClockTime
	
	local LightPart = script.Parent
	
	
	if Clocktime <= 17 then
		LightPart.BrickColor = BrickColor.new("Medium Stone Grey")
		LightPart.Material = ("SmoothPlastic")
	end
	
	if Clocktime >=18 then
		LightPart.BrickColor = BrickColor.new("Institutional White")
		LightPart.Material = ("Neon")
	end
end)
1 Like

Fixed! I needed to use a GetPropertyChangedSignal for it to work

local Clocktime = game.Lighting.ClockTime

local lightpart = script.Parent

game.Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
	local newtime = Clocktime
	if game.Lighting:GetMinutesAfterMidnight() > 6 * 60 then
		lightpart.Material = Enum.Material.Plastic
		lightpart.BrickColor = BrickColor.new("Medium stone grey")
	end
	if game.Lighting:GetMinutesAfterMidnight() > 18 * 60 then
		lightpart.Material = Enum.Material.Neon
		lightpart.BrickColor = BrickColor.new("Institutional white")
	end
end)

Good for you, good luck on your future projects :wink:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.