hi, I am making a working police lights, but I have a problem.
the issue is that when i click the police lights button (line 49, line 52), the lights are off. i click the button again and the lights would stay off instead of turning back on and flashing, although this realistically should not happen. due to function off making police_lights_on.value be false and at line 51 - 53, the next time i click the police lights button. the lights should be on and flashing
i can tell by that i don't get on (line 26) in output.
the local script is in player's PlayerGui.
the police_lights_on value is in police car model (server)
there is no error!
script:
---shortcuts
local car_value = script.car
local seat = car_value.Value.Chassis.VehicleSeat
local car = car_value.Value
local blue = car.Body.light_blue1
local rack_blue = car.Body.light_rack_blue
local rack_blue_front = car.Body.light_rack_blue_front
local rack_red = car.Body.light_rack_red
local rack_red_front = car.Body.light_rack_red_front
local red = car.Body.light_red
local gui = script["who actually made the original car, the scripts that aren't mine are absolute mayhem"]
---when button is pressed
function off()
print("off")
local lights = false
car.police_lights_on.Value = false
blue.BrickColor = BrickColor.Blue()
rack_blue.BrickColor = BrickColor.Blue()
rack_blue_front.BrickColor = BrickColor.Blue()
rack_red.BrickColor = BrickColor.Red()
rack_red_front.BrickColor = BrickColor.Red()
red.BrickColor = BrickColor.Red()
end
function on()
print("on")
local lights = true
car.police_lights_on.Value = true
repeat
wait(0.2)--(math.random(1, 10) / 10)
blue.BrickColor = BrickColor.Red()
rack_blue.BrickColor = BrickColor.Red()
rack_blue_front.BrickColor = BrickColor.Red()
rack_red.BrickColor = BrickColor.Blue()
rack_red_front.BrickColor = BrickColor.Blue()
red.BrickColor = BrickColor.Blue()
wait(0.2)--(math.random(1, 10) / 10)
blue.BrickColor = BrickColor.Blue()
rack_blue.BrickColor = BrickColor.Blue()
rack_blue_front.BrickColor = BrickColor.Blue()
rack_red.BrickColor = BrickColor.Red()
rack_red_front.BrickColor = BrickColor.Red()
red.BrickColor = BrickColor.Red()
until lights == false
end
---triggers
if car.police_lights_on.Value == true then
gui.Frame.TextButton.MouseButton1Click:Connect(off)
end
if car.police_lights_on.Value == false then
gui.Frame.TextButton.MouseButton1Click:Connect(on)
end

3 comments
Try adding the last 48 to 53 line in a while loop.
after line 48 replace it with this: car.police_lights_on:GetPropertyChangedSignal("Value"):Connect(function() if car.police_lights_on.Value then gui.Frame.TextButton.MouseButton1Click:Connect(off) end if not car.police_lights_on.Value then gui.Frame.TextButton.MouseButton1Click:Connect(on) end end)
yikes your gonna have a bad memory leak though since your connecting a lot