Struggling with making a streetlight script

Hey! So I am really confused on how to make a streetlight script. The old Roblox one just won’t work for me and I can’t find any tutorials that work! Does anyone have any code for this that they know works in 2020?

PS: I do not want a Day/Night cycle included in the script

1 Like

Uh I mean, there’s a billion ways to make one depending on how you want it to work. If you just want the script to change the light from green to yellow and then red, just make a While true do script which will wait() a certain amount of time, then turn the light to yellow (probably by setting its material), then repeat it again twice for red and back to green.

1 Like

I’m looking to do what is shown in this video.

Oh I thought you meant a traffic light. If you don’t want a day/night cycle, how do you want it to work? If you just want it to turn on and off repeatedly, make a while true do loop that cycles between setting the light’s material and color to one which appears to be glowing, and then doing the opposite. Use a wait() between each one.

Yeah not a traffic light bahaha. See the video I linked. I want to make it so if ClockTime is past 18 and before 6 then make the pointlight enabled, otherwise turn it off. Nothing I’ve tried has worked, any suggestions?

local lamps = --where your lamps are stored
game.Lighting.Changed:Connect(function()
local var = game.Lighting.ClockTime < 6 or game.Lighting.ClockTime > 18
for i,v in pairs(lamps:GetDescenants()) do
if v:IsA("Light") then
v.Enabled = var
end
end
end)

Written on mobile so it might not work.

3 Likes

I recommend declaring times in your day/night script where it reaches below/past a certain light level for your streetlights to turn off/on.

It didn’t work. Is there a specific place I should put this? What type of script should I use?

Here is a tutorial https://www.youtube.com/watch?v=OFGgTHlaWiA

Ahaha. That’s what I meant, I’m not sure why but it wouldn’t work.

Do It exactly how he did it then it will work.

Is there any errors?
This can be any script, a local or a server.
I recommend it being a server script and parenting it to ServerScriptService

Hmmm. No errors and I tried putting it in Server Script Service, nothing.

local lightPart = script.Parent
local PointLight = lightPart.PointLight

while true do
	wait(0.1)
	if game.Lighting:GetMinutesAfterMidnight() > 6*60 then
		lightPart.Material = Enum.Material.Plastic
		PointLight.Enabled = false
	end
	if game.Lighting:GetMinutesAfterMidnight() > 18*60 then
		lightPart.Material = Enum.Material.Neon
		PointLight.Enabled = true
	end
end

Nope, I think it’s outdated. No errors, no mistakes, no nothing. It just turns off the light and sets the material to plastic but won’t ever change to neon or enable anything no matter the time.