Need help with changing bool value

I need help with this script that will turn on and off the lights. I use this script to turn on the lights.

Mainveh = script.Parent

while true do
	wait(0)
	if script.Parent.On.Value  == true then
		Mainveh["Blue lights1"].Transparency = 0 -- Names of lights
		Mainveh["Blue lights2"].Transparency = 0
		Mainveh["Blue lights3"].Transparency = 0
		Mainveh["Blue lights4"].Transparency = 0
		Mainveh["Red light1"].Transparency = 1
		Mainveh["Red light2"].Transparency = 1
		Mainveh["Red light3"].Transparency = 1
		wait(0.12)
		Mainveh["Blue lights1"].Transparency = 1
		Mainveh["Blue lights2"].Transparency = 1
		Mainveh["Blue lights3"].Transparency = 1
		Mainveh["Blue lights4"].Transparency = 1
		Mainveh["Red light1"].Transparency = 0
		Mainveh["Red light2"].Transparency = 0
		Mainveh["Red light3"].Transparency = 0
		wait(0.12)
		Mainveh["Blue lights1"].Transparency = 0
		Mainveh["Blue lights2"].Transparency = 0
		Mainveh["Blue lights3"].Transparency = 0
		Mainveh["Blue lights4"].Transparency = 0
		Mainveh["Red light1"].Transparency = 1
		Mainveh["Red light2"].Transparency = 1
		Mainveh["Red light3"].Transparency = 1
		wait(0.12)
		Mainveh["Blue lights1"].Transparency = 1
		Mainveh["Blue lights2"].Transparency = 1
		Mainveh["Blue lights3"].Transparency = 1
		Mainveh["Blue lights4"].Transparency = 1
		Mainveh["Red light1"].Transparency = 0
		Mainveh["Red light2"].Transparency = 0
		Mainveh["Red light3"].Transparency = 0
	else
		Mainveh["Blue lights1"].Transparency = 1
		Mainveh["Blue lights2"].Transparency = 1
		Mainveh["Blue lights3"].Transparency = 1
		Mainveh["Blue lights4"].Transparency = 1
		Mainveh["Red light1"].Transparency = 1
		Mainveh["Red light2"].Transparency = 1
		Mainveh["Red light3"].Transparency = 1
	end
	end

This is what happens
robloxapp-20220515-1224267.wmv (3.5 MB)

If I start the game with the bool value off the lights will not be on. :police_car:

What is your issue? What are you trying to accomplish?

But What I saw is incorrect time span, also you need to change “script.Parent.On.Value” in game.

Mainveh = script.Parent
local waittime = 0.12 * 4

while true do
	if script.Parent.On.Value == true then
		Mainveh["Blue lights1"].Transparency = 0 -- Names of lights
		Mainveh["Blue lights2"].Transparency = 0
		Mainveh["Blue lights3"].Transparency = 0
		Mainveh["Blue lights4"].Transparency = 0
		Mainveh["Red light1"].Transparency = 1
		Mainveh["Red light2"].Transparency = 1
		Mainveh["Red light3"].Transparency = 1
		wait(0.12)
		Mainveh["Blue lights1"].Transparency = 1
		Mainveh["Blue lights2"].Transparency = 1
		Mainveh["Blue lights3"].Transparency = 1
		Mainveh["Blue lights4"].Transparency = 1
		Mainveh["Red light1"].Transparency = 0
		Mainveh["Red light2"].Transparency = 0
		Mainveh["Red light3"].Transparency = 0
		wait(0.12)
		Mainveh["Blue lights1"].Transparency = 0
		Mainveh["Blue lights2"].Transparency = 0
		Mainveh["Blue lights3"].Transparency = 0
		Mainveh["Blue lights4"].Transparency = 0
		Mainveh["Red light1"].Transparency = 1
		Mainveh["Red light2"].Transparency = 1
		Mainveh["Red light3"].Transparency = 1
		wait(0.12)
		Mainveh["Blue lights1"].Transparency = 1
		Mainveh["Blue lights2"].Transparency = 1
		Mainveh["Blue lights3"].Transparency = 1
		Mainveh["Blue lights4"].Transparency = 1
		Mainveh["Red light1"].Transparency = 0
		Mainveh["Red light2"].Transparency = 0
		Mainveh["Red light3"].Transparency = 0
		wait(0.12)
	else
		Mainveh["Blue lights1"].Transparency = 1
		Mainveh["Blue lights2"].Transparency = 1
		Mainveh["Blue lights3"].Transparency = 1
		Mainveh["Blue lights4"].Transparency = 1
		Mainveh["Red light1"].Transparency = 1
		Mainveh["Red light2"].Transparency = 1
		Mainveh["Red light3"].Transparency = 1
		wait(waittime)
	end
end

Is this a server script?
If so you changed the value on the client not the server

One thing to note with the time span is roblox’s built-in wait function isn’t very good, it’s affected by lag. I would recommend a custom wait module script for that Custom wait - the best solution to yielding!