Hey guys!
So I want a building to change the materials for it's windows according to the time and for some reason this doesn't work. Help?
Code:
local light = script.Parent.Model:GetChildren() for i = 1, #light do wait(0.1) if game.Lighting:GetMinutesAfterMidnight() > 6 * 60 then light[i].Material = Enum.Material.Plastic end if game.Lighting:GetMinutesAfterMidnight() > 18 * 60 then light[i].Material = Enum.Material.Neon end end
lightPart = workspace.lights:GetChildren() -- Table containing all of the lights function changeMaterial(material) for i, v in pairs(lightPart) do -- Iterates through all the lights v.Material = material -- Sets each light's material end end game.Lighting.Changed:connect(function(property) -- This will fire whenever the time changes, so that you don't have to use a 'while true do' loop if game.Lighting:GetMinutesAfterMidnight() == 6 * 60 then changeMaterial(Enum.Material.Plastic) -- Calls function to change light's material end if game.Lighting:GetMinutesAfterMidnight() == 18 * 60 then changeMaterial(Enum.Material.Neon) -- Calls function to change light's material end end)
Just change lightPart's location with wherever your Model with the lights is.
local light = script.Parent.Model:GetChildren() --if this doesn't work, then it has to do something with: if game.Lighting:GetMinutesAfterMidnight() > 6 * 60 for i = 1, #light do wait(0.1) if game.Lighting:GetMinutesAfterMidnight() > 6 * 60 then if light[i]:IsA('BasePart') then -- detects if it is a part light[i].Material = Enum.Material.Plastic end end if game.Lighting:GetMinutesAfterMidnight() > 18 * 60 then if light[i]:IsA('BasePart') then light[i].Material = Enum.Material.Neon end end end