Answered by
6 years ago Edited 6 years ago
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
01 | local lighting = game:GetService( "Lighting" ) |
02 | local building = script.Parent |
03 | local night = building:WaitForChild( "Night" ).Value |
04 | local day = building:WaitForChild( "Day" ).Value |
06 | lighting:GetPropertyChangedSignal( "ClockTime" ):Connect( function () |
07 | if lighting.ClockTime > = night then |
09 | building.Material = Enum.Material.Neon |
10 | elseif lighting.ClockTime > = day and lighting.ClockTime < night then |
11 | building.Material = Enum.Material.Plastic |