Alarm System problems

Hey there guys, what’s up?

So I have been trying to get into a bit of lua lately and I am stuck on this part here. You see, I am trying to make a button that, when clicked will search the workspace for every single brick named “AlarmLight” and then change the color of PointLight inside of that brick from red to white every second like an alarm indefinitely.

This is what I have so far

script.Parent.ClickDetector.MouseClick:connect(function()
while true do
	local alarmlight = game.Workspace:GetChildren("AlarmLight")
	for i = 1, #alarmlight do
		alarmlight.PointLight.Color = Color3.fromRGB(255,0,0)
		wait(1)
		alarmlight.PointLight.Color = Color3.fromRGB(0,0,0)
		wait(1)
	end
end
end)

I am still very much new, so I would appreciate any help and explanation as to what I should do or what your suggestion does.

Thank you!

2 Likes

Your issue here is you’re getting the children of the alarmlight model/part as opposed to searching the workspace for it like you intended.

Use a for loop to loop through your workspace to search for any parts named “alarmlight” then check if the part is actually named alarmlight then do whatever you wanna do with the lights. Try this, I haven’t actually tested it out so let me know whether it works. Also take note of the capitalisations:

script.Parent.ClickDetector.MouseClick:connect(function()
      for _, AlarmLight in pairs(workspace:GetChildren())
          if AlarmLight.Name == "AlarmLight" then
         while true do
           wait(1)
             AlarmLight.PointLight.Color = Color3.fromRGB(255,0,0)
	    wait(1)
	    AlarmLight.PointLight.Color = Color3.fromRGB(0,0,0)
	   wait(1)
end
end
end

Hey there, your script only seems to affect one AlarmLight brick, the others aren’t toggled.

I noticed you use Color, not Color3. Color3.fromRBG requires Color3
EDIT: Nevermind I realized you used a PointLight, I thought you were changing the brick color

script.Parent.ClickDetector.MouseClick:Connect(function()
    while true do
	    for i,alarm in pairs(workspace.AlarmLight:GetChildren()) do
		    alarm.PointLight.Color = Color3.fromRGB(255,0,0)
		    wait(1)
	    	alarm.PointLight.Color = Color3.fromRGB(0,0,0)
		    wait(1)
	    end
    end
end)

Make sure all your bricks are named the same.

I edited your part a bit and it partly works!

script.Parent.ClickDetector.MouseClick:Connect(function()
while true do
	for i,alarm in pairs(workspace:GetChildren("AlarmLight")) do
		if alarm.Name == "AlarmLight" then
			alarm.PointLight.Color = Color3.fromRGB(255,0,0)
			wait(1)
			alarm.PointLight.Color = Color3.fromRGB(0,0,0)
			wait(1)
		end
	end
end

end)

The problem is, that now those bricks light up one by one instead of all of them at the same time.

Try using

workspace.AlarmLight:GetChildren()

instead

1 Like

That only makes one of the AlarmLight bricks continuously go on and off, and not others.

1 Like

alarm = workspace.AlarmLight
script.Parent.ClickDetector.MouseClick:Connect(function()
while true do
for _,v in next, alarm:GetChildren() do
if v.Name == “PointLight” then
wait(.1)
v.Color = Color3.fromRGB(255,0,0)
delay(1, function()
v.Color = Color3.fromRGB(0, 0, 0)
end)
end
end
end
end)

I believe this works, excuse the indents lol

1 Like