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

Trying to toggle all alarms from a button, not working with no errors?

Asked by 3 years ago

This button I'm making is supposed to toggle on and off all of the spinning lights. There are no errors, but the ")" on the last "end" is red, and when i delete it, some of the script becomes underlined red too.

local button = script.Parent.ClickDetector -- your little button
local lights = game.Workspace.Lights:GetDescendants() -- your light 
local lights_are_on = false -- take a boolean value for the state of the light

button.MouseClick:connect(function()  -- Assuming that you have setup the Click Detector 
    for i, v in pairs (lights) do
        if v:IsA("SpotLight") then
    if not lights_are_on then -- check if the lights are on or not on
        lights.Enabled = true --  if they are not on, turn them on!
        lights_are_on = true -- Don't forget to check out litttle boolean that helps us alot!
    elseif lights_are_on then
        lights.Enabled = false--  if they are on, turn them off!
        lights_are_on = false -- so we know that they are off
    end
end)

1 answer

Log in to vote
0
Answered by
vra000 22
3 years ago

You forgot an "end" in your script. I'll help you fix it:

local button = script.Parent.ClickDetector -- your little button local lights = game.Workspace.Lights:GetDescendants() -- your light local lights_are_on = false -- take a boolean value for the state of the light

button.MouseClick:connect(function()  -- Assuming that you have setup the Click Detector 
    for i, v in pairs (lights) do
        if v:IsA("SpotLight") then
    if not lights_are_on then -- check if the lights are on or not on
        lights.Enabled = true --  if they are not on, turn them on!
        lights_are_on = true -- Don't forget to check out litttle boolean that helps us alot!
    elseif lights_are_on then
        lights.Enabled = false--  if they are on, turn them off!
        lights_are_on = false -- so we know that they are off
    end
end
end)
0
still doesnt work TheStarWarsMaster856 12 — 3y
Ad

Answer this question