How would I make Lights Flash when a Sound is Playing (Script ERROR)

So I am making a Vehicle in Roblox Studio and I wanted to make it a little more advanced. When I honk the Horn the Lights on the Lightbar should Rapidly Flash.

What is happening now is nothing… The script doesnt show any errors in the output but the Lights dont flash when the Horn Sound is playing.

I’ve tried While true loops, and If Statement, none have worked.

veh = script.Parent.Parent.Top
local white = Color3.fromRGB(189, 193, 255)
local red = Color3.fromRGB(196, 40, 28)
local blue = Color3.fromRGB(41, 59, 175)
local amber = Color3.fromRGB(213, 115, 61)

local Sound = script.Parent.Parent.Tones.Airhorn

if Sound.Playing == true then
	
	veh.T3.Lighto1.Color.ImageColor3 = white
	veh.T4.Lighto1.Color.ImageColor3 = white
	veh.T5.Lighto1.Color.ImageColor3 = white
	veh.T6.Lighto1.Color.ImageColor3 = white
	veh.T7.Lighto1.Color.ImageColor3 = white
	veh.T8.Lighto1.Color.ImageColor3 = white
	veh.T9.Lighto1.Color.ImageColor3 = white
	veh.T10.Lighto1.Color.ImageColor3 = white
	veh.T3.Lighto1.Enabled = true
	veh.T4.Lighto1.Enabled = true
	veh.T5.Lighto1.Enabled = true
	veh.T6.Lighto1.Enabled = true
	veh.T7.Lighto1.Enabled = true
	veh.T8.Lighto1.Enabled = true
	veh.T9.Lighto1.Enabled = true
	veh.T10.Lighto1.Enabled = true
	print("Started Flashing")
	task.wait(.02)
	veh.T3.Lighto1.Color.ImageColor3 = white
	veh.T4.Lighto1.Color.ImageColor3 = white
	veh.T5.Lighto1.Color.ImageColor3 = white
	veh.T6.Lighto1.Color.ImageColor3 = white
	veh.T7.Lighto1.Color.ImageColor3 = white
	veh.T8.Lighto1.Color.ImageColor3 = white
	veh.T9.Lighto1.Color.ImageColor3 = white
	veh.T10.Lighto1.Color.ImageColor3 = white
	veh.T3.Lighto1.Enabled = false
	veh.T4.Lighto1.Enabled = false
	veh.T5.Lighto1.Enabled = false
	veh.T6.Lighto1.Enabled = false
	veh.T7.Lighto1.Enabled = false
	veh.T8.Lighto1.Enabled = false
	veh.T9.Lighto1.Enabled = false
	veh.T10.Lighto1.Enabled = false
	task.wait(.02)
	print("Finished Flashing Cycle")	
	veh.T3.Lighto1.Color.ImageColor3 = white
	veh.T4.Lighto1.Color.ImageColor3 = white
	veh.T5.Lighto1.Color.ImageColor3 = white
	veh.T6.Lighto1.Color.ImageColor3 = white
	veh.T7.Lighto1.Color.ImageColor3 = white
	veh.T8.Lighto1.Color.ImageColor3 = white
	veh.T9.Lighto1.Color.ImageColor3 = white
	veh.T10.Lighto1.Color.ImageColor3 = white
	veh.T3.Lighto1.Enabled = true
	veh.T4.Lighto1.Enabled = true
	veh.T5.Lighto1.Enabled = true
	veh.T6.Lighto1.Enabled = true
	veh.T7.Lighto1.Enabled = true
	veh.T8.Lighto1.Enabled = true
	veh.T9.Lighto1.Enabled = true
	veh.T10.Lighto1.Enabled = true
	task.wait(.02)
	veh.T3.Lighto1.Color.ImageColor3 = white
	veh.T4.Lighto1.Color.ImageColor3 = white
	veh.T5.Lighto1.Color.ImageColor3 = white
	veh.T6.Lighto1.Color.ImageColor3 = white
	veh.T7.Lighto1.Color.ImageColor3 = white
	veh.T8.Lighto1.Color.ImageColor3 = white
	veh.T9.Lighto1.Color.ImageColor3 = white
	veh.T10.Lighto1.Color.ImageColor3 = white
	veh.T3.Lighto1.Enabled = false
	veh.T4.Lighto1.Enabled = false
	veh.T5.Lighto1.Enabled = false
	veh.T6.Lighto1.Enabled = false
	veh.T7.Lighto1.Enabled = false
	veh.T8.Lighto1.Enabled = false
	veh.T9.Lighto1.Enabled = false
	veh.T10.Lighto1.Enabled = false
	task.wait(.02)	
	veh.T3.Lighto1.Color.ImageColor3 = white
	veh.T4.Lighto1.Color.ImageColor3 = white
	veh.T5.Lighto1.Color.ImageColor3 = white
	veh.T6.Lighto1.Color.ImageColor3 = white
	veh.T7.Lighto1.Color.ImageColor3 = white
	veh.T8.Lighto1.Color.ImageColor3 = white
	veh.T9.Lighto1.Color.ImageColor3 = white
	veh.T10.Lighto1.Color.ImageColor3 = white
	veh.T3.Lighto1.Enabled = true
	veh.T4.Lighto1.Enabled = true
	veh.T5.Lighto1.Enabled = true
	veh.T6.Lighto1.Enabled = true
	veh.T7.Lighto1.Enabled = true
	veh.T8.Lighto1.Enabled = true
	veh.T9.Lighto1.Enabled = true
	veh.T10.Lighto1.Enabled = true
	task.wait(.02)
	veh.T3.Lighto1.Color.ImageColor3 = white
	veh.T4.Lighto1.Color.ImageColor3 = white
	veh.T5.Lighto1.Color.ImageColor3 = white
	veh.T6.Lighto1.Color.ImageColor3 = white
	veh.T7.Lighto1.Color.ImageColor3 = white
	veh.T8.Lighto1.Color.ImageColor3 = white
	veh.T9.Lighto1.Color.ImageColor3 = white
	veh.T10.Lighto1.Color.ImageColor3 = white
	veh.T3.Lighto1.Enabled = false
	veh.T4.Lighto1.Enabled = false
	veh.T5.Lighto1.Enabled = false
	veh.T6.Lighto1.Enabled = false
	veh.T7.Lighto1.Enabled = false
	veh.T8.Lighto1.Enabled = false
	veh.T9.Lighto1.Enabled = false
	veh.T10.Lighto1.Enabled = false
	task.wait(.02)	
	veh.T3.Lighto1.Color.ImageColor3 = white
	veh.T4.Lighto1.Color.ImageColor3 = white
	veh.T5.Lighto1.Color.ImageColor3 = white
	veh.T6.Lighto1.Color.ImageColor3 = white
	veh.T7.Lighto1.Color.ImageColor3 = white
	veh.T8.Lighto1.Color.ImageColor3 = white
	veh.T9.Lighto1.Color.ImageColor3 = white
	veh.T10.Lighto1.Color.ImageColor3 = white
	veh.T3.Lighto1.Enabled = true
	veh.T4.Lighto1.Enabled = true
	veh.T5.Lighto1.Enabled = true
	veh.T6.Lighto1.Enabled = true
	veh.T7.Lighto1.Enabled = true
	veh.T8.Lighto1.Enabled = true
	veh.T9.Lighto1.Enabled = true
	veh.T10.Lighto1.Enabled = true
	task.wait(.02)
	veh.T3.Lighto1.Color.ImageColor3 = white
	veh.T4.Lighto1.Color.ImageColor3 = white
	veh.T5.Lighto1.Color.ImageColor3 = white
	veh.T6.Lighto1.Color.ImageColor3 = white
	veh.T7.Lighto1.Color.ImageColor3 = white
	veh.T8.Lighto1.Color.ImageColor3 = white
	veh.T9.Lighto1.Color.ImageColor3 = white
	veh.T10.Lighto1.Color.ImageColor3 = white
	veh.T3.Lighto1.Enabled = false
	veh.T4.Lighto1.Enabled = false
	veh.T5.Lighto1.Enabled = false
	veh.T6.Lighto1.Enabled = false
	veh.T7.Lighto1.Enabled = false
	veh.T8.Lighto1.Enabled = false
	veh.T9.Lighto1.Enabled = false
	veh.T10.Lighto1.Enabled = false
	task.wait(.02)	
	veh.T3.Lighto1.Color.ImageColor3 = white
	veh.T4.Lighto1.Color.ImageColor3 = white
	veh.T5.Lighto1.Color.ImageColor3 = white
	veh.T6.Lighto1.Color.ImageColor3 = white
	veh.T7.Lighto1.Color.ImageColor3 = white
	veh.T8.Lighto1.Color.ImageColor3 = white
	veh.T9.Lighto1.Color.ImageColor3 = white
	veh.T10.Lighto1.Color.ImageColor3 = white
	veh.T3.Lighto1.Enabled = true
	veh.T4.Lighto1.Enabled = true
	veh.T5.Lighto1.Enabled = true
	veh.T6.Lighto1.Enabled = true
	veh.T7.Lighto1.Enabled = true
	veh.T8.Lighto1.Enabled = true
	veh.T9.Lighto1.Enabled = true
	veh.T10.Lighto1.Enabled = true
	task.wait(.02)
	veh.T3.Lighto1.Color.ImageColor3 = white
	veh.T4.Lighto1.Color.ImageColor3 = white
	veh.T5.Lighto1.Color.ImageColor3 = white
	veh.T6.Lighto1.Color.ImageColor3 = white
	veh.T7.Lighto1.Color.ImageColor3 = white
	veh.T8.Lighto1.Color.ImageColor3 = white
	veh.T9.Lighto1.Color.ImageColor3 = white
	veh.T10.Lighto1.Color.ImageColor3 = white
	veh.T3.Lighto1.Enabled = false
	veh.T4.Lighto1.Enabled = false
	veh.T5.Lighto1.Enabled = false
	veh.T6.Lighto1.Enabled = false
	veh.T7.Lighto1.Enabled = false
	veh.T8.Lighto1.Enabled = false
	veh.T9.Lighto1.Enabled = false
	veh.T10.Lighto1.Enabled = false
	task.wait(.02)	
	end

if Sound.Playing == false then
	
	veh.T3.Lighto1.Enabled = false
	veh.T4.Lighto1.Enabled = false
	veh.T5.Lighto1.Enabled = false
	veh.T6.Lighto1.Enabled = false
	veh.T7.Lighto1.Enabled = false
	veh.T8.Lighto1.Enabled = false
	veh.T9.Lighto1.Enabled = false
	veh.T10.Lighto1.Enabled = false
	end



you could use changed function
Ex:

Part.Changed:Connect(function(transparency)
	
end)

Though I suggest just changing it the lights with the script that causes sound to play

It is a Police Vehicle, so When the Horn Honk, the Front Lights on the Lightbar should Flash White Rapidly.

yeah soo, when you honk the horn change the lights and play sound, then after sound stops playing (you can detect this with audio.Ended:Wait()) turn the lights off

Oh dear lord.

Please use a number loop…

local function flashLights()
	for i = 3, 10 do
		veh["T" .. i].Lighto1.Color.ImageColor3 = white
		veh["T" .. i].Lighto1.Enabled = true
	end
	wait(0.02)
	for i = 3, 10 do
		veh["T" .. i].Lighto1.Color.ImageColor3 = white
		veh["T" .. i].Lighto1.Enabled = false
	end
	wait(0.02)
end

if Sound.Playing then
	print("Started Flashing")
	for _ = 1, 3 do
		flashLights()
	end
	wait(0.02)
	print("Finished Flashing Cycle")
	for _ = 1, 3 do
		flashLights()
	end
	wait(0.02)
else
	for i = 3, 10 do
		veh["T" .. i].Lighto1.Enabled = false
	end
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.