lightpart.Color
takes a Color3 value, not a string. You can learn more about that here.
That line should look like the following,
lightpart.Color = Color3.fromRGB(27, 42, 53)
lightpart.BrickColor
takes a BrickColor
value, not a string. You can learn more about that here.
That line should look like the following,
lightpart.BrickColor = BrickColor.new("Deep orange")
Here is some tips for performance. The time between lighting updates and part refreshing may not always align so you may see a slight delay when updating your part. This gets fixed with connections. In short, they “tell” us exactly when something happens. in this case, we are detecting when the time changes.
We can also make 6 * 60
, 18 * 60
, and Lighting
variables because we know they will never change. (not property-wise)
Lastly, if the time updates and it is still morning, we do not need to update the part’s values which is done with the isDay
variable.
local lightingService = game:GetService("Lighting") -- game.Lighting
local morningTime = 6 * 60
local nightTime = 18 * 60
local isDay = nil
local function updatePart()
local currentTime = lightingService:GetMinutesAfterMidnight()
if currentTime > morningTime and currentTime < nightTime then -- checks if time is between morning and evening
if isDay ~= true then -- checks if it is not already morning
isDay = true
-- set your model to be morning
end
elseif isDay ~= false then -- checks if it is not already night
isDay = false
-- set your model to be night
end
end
lightingService:GetPropertyChangedSignal("TimeOfDay"):Connect(updatePart) -- runs the code within updatePart() when Lighting.TimeOfDay is changed
updatePart() -- ypdates to make sure part matches with time of day when game loads
Code blocks, typed with 3 “" followed by another 3 "
,” make copying code easy for developers so they cut put it into their code editors to review and change, try it out!