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:
01 | local light = script.Parent.Model:GetChildren() |
02 |
03 | for i = 1 , #light do |
04 | wait( 0.1 ) |
05 | if game.Lighting:GetMinutesAfterMidnight() > 6 * 60 then |
06 | light [ i ] .Material = Enum.Material.Plastic |
07 | end |
08 | if game.Lighting:GetMinutesAfterMidnight() > 18 * 60 then |
09 | light [ i ] .Material = Enum.Material.Neon |
10 | end |
11 | end |
01 | lightPart = workspace.lights:GetChildren() -- Table containing all of the lights |
02 |
03 | function changeMaterial(material) |
04 | for i, v in pairs (lightPart) do -- Iterates through all the lights |
05 | v.Material = material -- Sets each light's material |
06 | end |
07 | end |
08 |
09 | 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 |
10 | if game.Lighting:GetMinutesAfterMidnight() = = 6 * 60 then |
11 | changeMaterial(Enum.Material.Plastic) -- Calls function to change light's material |
12 | end |
13 | if game.Lighting:GetMinutesAfterMidnight() = = 18 * 60 then |
14 | changeMaterial(Enum.Material.Neon) -- Calls function to change light's material |
15 | end |
16 | end ) |
Just change lightPart's location with wherever your Model with the lights is.
01 | local light = script.Parent.Model:GetChildren() |
02 | --if this doesn't work, then it has to do something with: if game.Lighting:GetMinutesAfterMidnight() > 6 * 60 |
03 |
04 | for i = 1 , #light do |
05 | wait( 0.1 ) |
06 | if game.Lighting:GetMinutesAfterMidnight() > 6 * 60 then |
07 | if light [ i ] :IsA( 'BasePart' ) then -- detects if it is a part |
08 | light [ i ] .Material = Enum.Material.Plastic |
09 | end |
10 | end |
11 | if game.Lighting:GetMinutesAfterMidnight() > 18 * 60 then |
12 | if light [ i ] :IsA( 'BasePart' ) then |
13 | light [ i ] .Material = Enum.Material.Neon |
14 | end |
15 | end |
16 | end |