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 ‘)’ "
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…
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
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
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.
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)