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

Problem with scripting a series of flashing lights. Any help please?

I am a newbie at scripting and acquire serious help. My friend wants me to script him a series of flashing lights(Parts that change material one at a time which will conclude a series of flashing lights after night time arrives and the time needed to change material is at least 1 second). Everything went accordingly to my script(which is showcased below) until the neon parts began slowing down and then randomly started flashing around without being in sync. Any help please?

local lightPart = script.Parent

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

1 answer

✓ Accepted answer

Edit: I have changed the script below because the problem is that the lights flash at irregular intervals, from what I can see.

Try this:

local debounce = false

game.Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
	if debounce == true then return end
	if game.Lighting.ClockTime > 18 then
		debounce = true
		repeat
			lightPart.Material = Enum.Material.Neon
			wait(1)
			lightPart.Material = Enum.Material.Plastic
			wait(1)
		until game.Lighting.ClockTime >= 6 and game.Lighting.ClockTime < 6.01
		debounce = false
 	end
end)

2 comments

0

Nope. Just attempted this right now and it still slows down and manages to randomly flash.

0

Change "wait(3)" on line 11 to wait(1). I put "3" there as that is what your initial script would have done, but if the problem is that it flashes randomly, then, if you look at the script, it actually changes the material to plastic (non-lit) 3 times in a row, and the pattern is a little irregular. I have edited my script above.

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