Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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)

1 comment

0

still doesnt work

This discussion is preserved as it was. New answers, comments, and votes are closed.