Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

police lights should be on and flashing next time i click the lights button, but they stay off?!

Asked by 2 years ago
Edited 2 years ago

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
0
Try adding the last 48 to 53 line in a while loop. SuperPuiu 497 — 2y
0
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) MarkedTomato 810 — 2y
0
yikes your gonna have a bad memory leak though since your connecting a lot MarkedTomato 810 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago
---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"]

local function police_light_function()
   if car.police_lights_on.Value then
        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()
   else
        print("on")
        local lights = true
        car.police_lights_on.Value = true
        repeat
        task.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()
        task.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
end

gui.Frame.TextButton.MouseButton1Click:Connect(police_light_function)

Since this is a LocalScript, only the player that clicked the button will see it.

task.wait() is 2 times faster than wait() or can be a lot faster depending on the client's FPS, thus task.wait() should be used instead.

Ad

Answer this question