How can i make a block that changes an value?

Hello guys, I have a problem. I wanna create a block that has an ClickDetector that changes an value of a diffrent model to true. This is very important so i can finish my police cars.
This is how the Police lights look now orlbox
–the L1 till L10 are the lights
the on is the value
and there’s a script that includes this

Model=script.Parent
while true do
	wait()
	if Model.on.Value == true then
		wait(0.1)
	Model.L1.Transparency=0
	Model.L2.Transparency=0
	Model.L3.Transparency=0
	Model.L4.Transparency=0
	Model.L5.Transparency=0
	Model.L6.Transparency=1
	Model.L7.Transparency=1
	Model.L8.Transparency=1
	Model.L9.Transparency=1
	Model.L10.Transparency=1
	
	wait(0.2)
	Model.L1.Transparency=1
	Model.L2.Transparency=1
	Model.L3.Transparency=1
	Model.L4.Transparency=1
	Model.L5.Transparency=1
	Model.L6.Transparency=0
	Model.L7.Transparency=0
	Model.L8.Transparency=0
	Model.L9.Transparency=0
		Model.L10.Transparency=0
		
	end
end

And i wanna create a button that changes the “on” value to true when i press a button
This is how it looks like now
poloc
The Script you see is how i’m going to change the value, but i dont know how to do that because i’m new at scripting
I hope you can help me.

You can use ClickDetector.MouseClick and connect a function into it.

You could use something like this

Script in the PoliceButtons

local value = --Where the value is located, do not put .Value, just reference the BaseValue instance

local detector = script.Parent.ClickDetector

detector.MouseClick:Connect(function()
    value.Value = not value.Value
end)

Should do what you need

Model = script.Parent
while true do
	if Model.on.Value == true then
	wait(0.2)
	Model.L1.Transparency=0
	Model.L2.Transparency=0
	Model.L3.Transparency=0
	Model.L4.Transparency=0
	Model.L5.Transparency=0
	Model.L6.Transparency=1
	Model.L7.Transparency=1
	Model.L8.Transparency=1
	Model.L9.Transparency=1
	Model.L10.Transparency=1
	
	wait(0.2)
	Model.L1.Transparency=1
	Model.L2.Transparency=1
	Model.L3.Transparency=1
	Model.L4.Transparency=1
	Model.L5.Transparency=1
	Model.L6.Transparency=0
	Model.L7.Transparency=0
	Model.L8.Transparency=0
	Model.L9.Transparency=0
	Model.L10.Transparency=0
        else
              wait(1)
	end
end

Just a fix to the timing. You have some wait()s placed incorrectly.

Weird, it didnt worked. There’s a red underline on the local detector.
hmmm

It’s because you directly copied my code and didn’t change the value variable, the comment was meant to show you that you have to get the location of the bool value you want to change.

Example, say your value is in a part in workspace, you’d do

local value = workspace.Part.BoolValue

do that, but replace workspace.Part.BoolValue with your BoolValue location

Thank you so much man. I’ve been stuck there for 2 weeks straight. Can you do a code where you can set the Value to false again?

It alreayd doe sthat, value.Value = not value.Value means invert. true become sfalse and false becomes true

Sorry for being months late, but when i turn off the light, only the blue light stays on, it should turn off both lights (blue and red)