Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Runway lighting script not working, despite having a day/night cycle that does work. Any help?

I'm making a Runway Lighting system for my airport, but apparently the script I made is not working properly for any sort of reason. I got 2 scripts, one for the day/night cycle (which works), and the other to turn off the light once 6AM has hit, and it should turn back on once 6PM has hit. But it doesn't, so any help would be appreciated.

Day/Night Cycle Script

minutesAfterMidnight = 0
while true do
	minutesAfterMidnight = minutesAfterMidnight + 10
	game.Lighting:SetMinutesAfterMidnight(minutesAfterMidnight)
	wait(.1)
end

Runway Lighting Script

while true do
	if game.Lighting.ClockTime > 6
		script.Parent.Light.Enabled = false
		script.Parent.Material = "Smoothplastic"
	end
	if game.Lightning.ClockTime > 18
		script.Parent.Light.Enabled = true
		script.Parent.Material = "Neon"
	end
end

1 comment

0

Small note for the Day/Night Cycle: I made it +10 for fast forwarding a bit to see if the Runway Lighting script works. Hence why it's so high.

3 answers

✓ Accepted answer

There are a lot of small errors in your ligthting script. You are mission the then from youe if statmenets and you have the incorrect name on like 7 Lightning and lastly Smoothplastic is not a valid material name it should be SmoothPlastic

The second script will error and not run which you should have seen in your output.

It would be best to put this all in the same loop as you need to reach a set time of the day then enable / disable the lights.

Example:-

-- services
local lighting = game:GetService('Lighting')

local function disableLights()
	workspace.Part.Material = Enum.Material.SmoothPlastic
	workspace.Part.Light.Enabled = false
end

local function enableLights()
	workspace.Part.Material = Enum.Material.Neon
	workspace.Part.Light.Enabled = true
end

while true do
	-- day to night
	disableLights() -- disable light 
	for i=360, 960, 10 do -- loop to night
	    lighting:SetMinutesAfterMidnight(i)
	    wait(.1)
	end
	
	-- night to day
	enableLights() -- enable lights
	for i=960, 1800, 10 do -- loop to day
		lighting:SetMinutesAfterMidnight(i)
		wait(.1)
	end
end

I hope this helps.

3 comments

0

The script works, but the Day/Night Cycle is moving way too fast. And since I'm not familiar with this kind of scripting, how do I make it progress slower? Say like, 5 minutes for a whole day.

0

Nevermind, I already found it. Thanks for the help.

0

no problem

It isn’t working because you don’t check game time with Lighting.ClockTime, but check it with Lighting:GetMinutesAfterMidnight(). Another error is on lines 4 and 8. You don’t set Enum properties like that. You would set the property of Material like this:

Part.Material = Enum.Material.Neon

not:

Part.Material = "Neon"

local Lighting = game:GetService"Lighting"

while wait() do
    if Lighting:GetMinutesAfterMidnight() == 6 then
        script.Parent.Light.Enabled = false
        script.Parent.Material = Enum.Material.SmoothPlastic
    end
    
    if Lighting:GetMinutesAfterMidnight() == 18 then
        script.Parent.Light.Enabled = false
        script.Parent.Material = Enum.Material.Neon
    end
end

4 comments

0

Enum.Material.Neon is the same thing as "Neon". Just most scripters recommend enumeration.

0

Why put a string where a enum is expected? It’s like trying to put a string as a value for an IntValue.

0

Copied it 100% into my script, and it doesn't work either.

0

what is wrong with checking the time through clocktime? for me it seems to work better then minutesaftermidnight

I have


local lighting = game:GetService('Lighting')


while true do	
	i = lighting:GetMinutesAfterMidnight() + 10
	lighting:SetMinutesAfterMidnight(i)
	wait(.1)
end

for day night system and

local Lighting = game:GetService"Lighting"

while wait() do
    if game.Lighting.ClockTime > 6 and  game.Lighting.ClockTime < 18 then
  	 script.Parent.PointLight.Enabled = false
     script.Parent.Material = Enum.Material.SmoothPlastic
    end

    if game.Lighting.ClockTime > 18 then
	 script.Parent.PointLight.Enabled = true
     script.Parent.Material = Enum.Material.Neon
    end
end

for turning the lights on. this seems to work perfectly for me but I'm open for comments :)

This discussion is preserved as it was. New answers, comments, and votes are closed.