Hello developers! I need help with this script. What I want to achieve is for this script to turn the lights off during the day and turn them back on during the night. Here is the script:
local Part = script.Parent
local pointLight = Part.PointLight
while true do
wait(0.1)
if game.Lighting:GetMinutesAfterMidnight() > 6 * 60 then
Part.Material = Enum.Material.Plastic
pointLight.Enabled = false
end
if game.Lighting:GetMinutesAfterMidnight() > 18 * 60 then
Part.Material = Enum.Material.Neon
pointLight.Enabled = true
end
end
The problem is that when I first spawn in, the lights stay on. Is there a way to fix it? God bless you.
You are only considering when time is bigger than 6 and 18. You have to make another if statement that checks whether the time is earlier than 6 or not.
local Lighting = game:GetService("Lighting")
local Part = script.Parent
local pointLight = Part:WaitForChild("PointLight")
while wait() do
if Lighting:GetMinutesAfterMidnight() > 6 * 60 or Lighting:GetMinutesAfterMidnight() < 18 * 60 then
Part.Material = Enum.Material.Plastic
pointLight.Enabled = false
elseif Lighting:GetMinutesAfterMidnight() > 18 * 60 or Lighting:GetMinutesAfterMidnight() < 6 * 60 then
Part.Material = Enum.Material.Neon
pointLight.Enabled = true
end
end
Edit: Found a little mistake in the code, just fixed it.