✓ Accepted answer
This will only ever run once.
local lightPart = game.Workspace.LightPart
game.Lighting.LightingChanged:connect(function()
local timeAfterMidnight = game.Lighting:GetMinutesAfterMidnight()
if timeAfterMidnight >= 8 * 60 and timeAfterMidnight <= 18 * 60 then
lightPart.Material = Enum.Material.Plastic
lightPart.PointLight.Enabled = false
elseif timeAfterMidnight >= 18* 60 and timeAfterMidnight <= 8 * 60 then
lightPart.Material = Enum.Material.Neon
lightPart.PointLight.Enabled = true
end
end)
You need to use a loop to run the function constantly.
For multiple parts
Scenario I have a folder in workspace called "Lights". It has many parts in it.
local lightStorage = game.Workspace.Lights:GetChildren()
game.Lighting.LightingChanged:connect(function()
local timeAfterMidnight = game.Lighting:GetMinutesAfterMidnight()
if timeAfterMidnight >= 8 * 60 and timeAfterMidnight <= 18 * 60 then
for i,v in pairs(lightStorage) do
v.Material = Enum.Material.Plastic
v.PointLight.Enabled = false
end
elseif timeAfterMidnight >= 18* 60 and timeAfterMidnight <= 8 * 60 then
for i,v in pairs(lightStorage) do
v.Material = Enum.Material.Neon
v.PointLight.Enabled = true
end
end
end)
1 comment
Added some information to my answer.