Hello , I got probblem again ! And I hope you’ll help me to solve this quize , I got a lightning and used lighting - ClockTime to make windows neon material while night and smooth plastic while day . So that script what I have , I also have day cycle script , but it works correctly .
Here the script in window
local daytime = game.Lighting.ClockTime
local window = script.Parent
if daytime >= 6 or daytime <= 18 then
window.Material = Enum.Material.SmoothPlastic
elseif daytime < 6 or daytime > 18 then
window.Material = Enum.Material.Neon
end
local light = game.Lighting
local window = script.Parent
light:GetPropertyChangedSignal("ClockTime"):Connect(function(daytime)
if daytime >= 6 or daytime <= 18 then
window.Material = Enum.Material.SmoothPlastic
elseif daytime < 6 or daytime > 18 then
window.Material = Enum.Material.Neon
end
end)
Your script fires once, rather than every time it is changed. Mine checks if a value (aka ClockTime) has been changed.
There is a logical error in the script. if daytime >=6 or daytime <= 18 then
The issue with this line right here is that it will always return true. Since this line runs first in the if statement, it will always proceed to turn the window material to smooth plastic. Because of this, you should be using and instead of or in this if statement.
To explain why you should use and more clearly, lets say the time in game was 8pm, or clocktime = 20. The script checks, is it greater than or equal to 6? That is true, and because it is part of an or statement it never needs to check the second check (daytime <= 18) to return true because an or statement will return true as long as at least one condition is true.
local light = game.Lighting
local window = script.Parent
light:GetPropertyChangedSignal("ClockTime"):Connect(function(daytime)
if daytime >= 6 and daytime <= 18 then
window.Material = Enum.Material.SmoothPlastic
elseif daytime < 6 or daytime > 18 then
window.Material = Enum.Material.Neon
end
end)
Note: I assume you are using another script or function to change the time? If not, you will need to use game.Lighting:SetMinutesAfterMidnight() in some sort of loop or regular event.
I made like you said and it doesn’t make material neon when night and plastic when day , why ?
This is script what you said me to use
local light = game.Lighting
local window = script.Parent
light:GetPropertyChangedSignal("ClockTime"):Connect(function(daytime)
if daytime >= 6 and daytime <= 18 then
window.Material = Enum.Material.SmoothPlastic
elseif daytime < 6 and daytime > 18 then
window.Material = Enum.Material.Neon
end
end)
local light = game.Lighting
local window = script.Parent
light:GetPropertyChangedSignal("ClockTime"):Connect(function(daytime)
if daytime >= 6 and daytime <= 18 then
window.Material = Enum.Material.SmoothPlastic
else
window.Material = Enum.Material.Neon
end
end)
Also, the time should be changing in order for the script to fire.
The script should theoretically be working. Is there any print from the output? Perhaps the issue has to do with something other than the actual code in the script itself.