Hi! I am making a building with twenty windows. I want the windows to change its material to neon if it is nighttime. I don't want to change each property of the windows one by one, as the script would be so long and messy.
The script below is my current script:
-- Defining the variables.
local day = game.Workspace.Buttons.Day
local night = game.Workspace.Buttons.Night
local windows = game.Workspace.Windows -- Windows is the name of my model containing the 20 parts.
-- Script for day and night.
day.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
game.Lighting.TimeOfDay = "00:00:00"
end
end)
night.Touched:Connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
game.Lighting.TimeOfDay = "14:00:00"
end
end)
-- This is the script for the windows. It works fine but it is so long and repetitive. People say it's bad practice.
if game.Lighting == "00:00:00" then
game.Windows.FirstPart.Material = Enum.Material.Neon
game.Windows.SecondPart.Material = Enum.Material.Neon
game.Windows.ThirdPart.Material = Enum.Material.Neon
game.Windows.FourthPart.Material = Enum.Material.Neon
game.Windows.FifthPart.Material = Enum.Material.Neon
-- 15 more Enum.Material.Neon lines.
elseif game.Lighting == "14:00:00" then
game.Windows.FirstPart.Material = Enum.Material.SmoothPlastic
game.Windows.SecondPart.Material = Enum.Material.SmoothPlastic
game.Windows.ThirdPart.Material = Enum.Material.SmoothPlastic
game.Windows.FourthPart.Material = Enum.Material.SmoothPlastic
game.Windows.FifthPart.Material = Enum.Material.SmoothPlastic
-- 15 more Enum.Material.SmoothPlastic lines.
end
The script works as it should but is there any way to shorten this?

3 comments
Definitely! I'll work on an answer.
Answered!
Please accept my answer if it helped!