✓ Accepted answer
GENERAL PRACTICE
Use :GetService() to retrieve Lighting
Use :WaitForChild() to make sure an item exists before changing it.
Make sure to use local variables when a line, like "building" is meant to be inside a function that is not global.
Material is an Enum, not a String, so while the string may work some of the time, it is not always guaranteed.
Since you are checking that the ClockTime is greater than the day and night values, also make sure to have a check that the time is less than the night so the "day" change can run.
ISSUES
Your code needs to be placed within a function to work multiple times with the same activating requirements. Without the function, the code will only run once at the time the server is created. In the below example, I've used a :GetPropertyChangedSignal() to determine that the ClockTime of the Lighting is changed (as opposed to Brightness or another property).
REVISED SERVER SCRIPT
local lighting = game:GetService("Lighting")
local building = script.Parent
local night = building:WaitForChild("Night").Value
local day = building:WaitForChild("Day").Value
lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
if lighting.ClockTime >= night then
wait(1)
building.Material = Enum.Material.Neon
elseif lighting.ClockTime >= day and lighting.ClockTime < night then
building.Material = Enum.Material.Plastic
end
end)
3 comments
hmmm clean it please?
You put it incorrectly..
I try to make it correct XD doesn't work