Click here to Skip to main content
16,022,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone
I am trying to make the lights on a police car keep flashing, but the while loop I am using does not work.

The Output shows that the wait loops does not function, and I have used print statements to see where the issue was. Please help

What I have tried:

local blue = script.Parent.Blue
local red = script.Parent.Red

--Flashing lights
while true do
	red.Material = "SmoothPlastic"
	red.SpotLight.Brightness = 1
	blue.Material = "Neon"
	blue.SpotLight.Brightness = 3
	print('Blue Lights Activated')
	wait(2)
	print('Waiting Procedure')
	wait(0.1)
	red.Material = "Neon"
	red.SpotLight.Brightness = 3
	blue.Material = "SmoothPlastic"
	blue.SpotLight.Brightness = 1
	print('Red Lights Activated')
end

local blue = script.Parent.Blue
local red = script.Parent.Red

--Flashing lights
for i=1, 1000 do
	red.Material = "SmoothPlastic"
	red.SpotLight.Brightness = 1
	blue.Material = "Neon"
	blue.SpotLight.Brightness = 3
	print('Blue Lights Activated')
	wait(2)
	print('Waiting Procedure')
	wait(0.1)
	red.Material = "Neon"
	red.SpotLight.Brightness = 3
	blue.Material = "SmoothPlastic"
	blue.SpotLight.Brightness = 1
	print('Red Lights Activated')
end
Posted
Updated 22-May-21 4:52am

1: There is no wait after red lights, using for i=1, 1000 do makes it glitchy and more. Here is a fixed version:

Lua
local red = script.Parent.red
local blue = script.Parent.blue

local open = true -- You can edit how it will open / close by if function.

while open == true do
	red.Material = Enum.Material.SmoothPlastic
	red.SpotLight.Brightness = 1
	blue.Material = Enum.Material.Neon
	blue.SpotLight.Brightness = 3
	print('Blue Lights Activated')
	wait(0.8)
	print('Waiting Procedure')
	wait(0.1)
	red.Material = Enum.Material.Neon
	red.SpotLight.Brightness = 3
	blue.Material = Enum.Material.SmoothPlastic
	blue.SpotLight.Brightness = 1
	print('Red Lights Activated')
	wait(0.8)
	print('Waiting Procedure') -- Makes it retry wait.
	wait(0.1)
end


in this code:

* We edited how material will change. Material cannot be changed with "" and it must be used by Enum.Material.material

* We edited waiting time, 2 is a pretty slow time for a police car lights.

* We maked an new variable named "open" and this variable can be changed by an if function. This variable makes the main function works.

* We changed "for i = 1,1000 do" and instead of that, we did "while open == true do" and this script makes if open equals true, then run the script.

This is all! Don't forget to make 5 stars on this! Thanks.
 
Share this answer
 
Comments
Richard Deeming 28-Jun-24 11:28am    
Aside from the fact that you're three years too late, begging for "5 stars" on your answers makes it obvious that you are rep-point hunting. That's a great way to get banned from the site as a troll!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900