[SOLVED] The worst enemy of scripting, now in my script

So. I am making a script that of a push of a button triggers a panic alarm, however, it seems that it "expected ‘end’ (to close do at line 11), got ‘else’ "

Here is the code:

local Clicky = script.Parent.ClickDetector
local Sound = workspace.Alarm["Alarm"]
breach = false
debounce = false
Clicky.MouseClick:Connect(function()
	if not debounce then
		debounce = true

print("Breach button pressed.")
if breach == false then
for _, object in pairs(workspace.Lights:GetChildren()) do
       object.BrickColor = BrickColor.Red
       
Sound:Play()
breach = true
debounce = false


else
	

for _, object in pairs(workspace.Lights:GetChildren()) do
		object.BrickColor = BrickColor.White
		Sound:Stop()
		debounce = false
		breach = false
end
end
end)

I absolutely LOATHE people who ask to be spoonfed for code, so sorry if I am but what am I doing wrong here?
I’ve already tried putting end before else, but it always results in "Expected identifier when parsing expression, got ‘)’ "

1 Like

Exactly as the error states. You are missing an end statement for one of your blocks.

Please properly indent and read the errors carefully.
You are also just randomly doing object.PointLight = without even giving it anything…

2 Likes
local Clicky = script.Parent.ClickDetector
local Sound = workspace.Alarm["Alarm"]
breach = false
debounce = false
Clicky.MouseClick:Connect(function()
if not debounce then
	debounce = true

print("Breach button pressed.")
if breach == false then
for _, object in pairs(workspace.Lights:GetChildren()) do
   object.BrickColor = BrickColor.Red
   object.PointLight = --Nil?
Sound:Play()
breach = true
debounce = false
end

else


for _, object in pairs(workspace.Lights:GetChildren()) do
	object.BrickColor = BrickColor.White
	Sound:Stop()
	debounce = false
	breach = false
end
end
end)

Example:

if a then
for i,v in pairs(game.Workspace:GetChildren()) do
print(i.." Workspace:"..v.Name)
    -- MISSING END HERE
else
for i,v in pairs(game.Lighting:GetChildren()) do
print(i.." Lightning:"..v.Name)
end
end

Output: Expected end to close do at line 2

Fix:

if a then
for i,v in pairs(game.Workspace:GetChildren()) do
print(i.." Workspace:"..v.Name)
end--End Exists
else
for i,v in pairs(game.Lighting:GetChildren()) do
print(i.." Lightning:"..v.Name)
end
end
2 Likes

I forgot to put this in the original post, sorry. I had already tried than and lo and behold: "Expected identifier when parsing expression, got ‘)’ "

1 Like
object.PointLight = 

and a syntax error here, line 13? I think

2 Likes

It is expecting a variable or keyword or something and you are instead giving it parenthesis. Check your parenthesis on that line. Most of these errors are completely straightforward

1 Like

Alright, disregard that. Sorry. Even without that the error still persists.

1 Like

You probably forgot ANOTHER end statement for the if statement so it is thinking end) is the end for the if statement of the debounce check instead of the function being connected. Again, please properly indent and don’t forget to finish every block with an end even if you have not finished writing it yet.

2 Likes
local Clicky = script.Parent:WaitForChild("ClickDetector")
local Sound = workspace:WaitForChild("Alarm"):WaitForChild("Alarm")
local lights = game.Workspace:WaitForChild("Lights")
breach = false
debounce = false

Clicky.MouseClick:Connect(function()
    if not debounce then
        debounce = true
	print("Breach button pressed.")
	if breach == false then
	    for _, object in pairs(lights:GetChildren()) do
	        object.BrickColor = BrickColor.Red
		Sound:Play()
		breach = true
		debounce = false
	    end
	end
    else
	for _, object in pairs(lights:GetChildren()) do
	    object.BrickColor = BrickColor.White
	    Sound:Stop()
	    debounce = false
	    breach = false
	end
    end
end)
2 Likes

Alright. thank you. I seem to have fixed it. There is only one solution I marked but you all helped me!
Thank you all!

1 Like

Glad to hear that! :slight_smile:

2 Likes