Alarm System not working

So when I press the Onbutton it Plays the song correctly, changes the color, and changes the PointLight but it’s only working on 1 Part instead of all the parts. Any solutions?

On-Script

function onClicked()

game.Workspace.Part.Part.Color = Color3.fromRGB(0, 0, 0)

game.Workspace.Alarms.Subscribe:Play()

game.Workspace.Part.Part.SurfaceLight.Color = Color3.fromRGB(255, 0, 0)

end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

Off Script

function onClicked()

game.Workspace.Part.Part.Color = Color3.fromRGB(127, 127, 127)

game.Workspace.Alarms.Subscribe:Pause()

game.Workspace.Part.Part.SurfaceLight.Color = Color3.fromRGB(255, 255, 255)

end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

You need a for loop to iterate all the parts

workspace.Alarms.Subscribe:Play()
for i, Part in pairs(workspace:GetChildren()) do
    if Part.Name == "Part" and Part:FindFirstChild'Part' then
        Part.Part.Color = Color3.fromRGB(0, 0, 0)
        Part.Part.SurfaceLight.Color = Color3.fromRGB(255, 0, 0)
    end
end

Tried it no success,

    function onClicked()

	workspace.Alarms.Subscribe:Play()
	for i, Part in pairs(workspace:GetChildren()) do
		if Part.Name == "Part" and Part:FindFirstChild'Part' then
			Part.Part.Color = Color3.fromRGB(0, 0, 0)
			Part.Part.SurfaceLight.Color = Color3.fromRGB(255, 0, 0)
		end
	end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

Edit the colour values if that’s the issue

Can you show the hierarchy of the explorer with the parts visible?

The Parts are in a Folder named “Lights”

Instead of workspace:GetChildren() do workspace.Lights:GetChildren()

1 Like

I got it working thanks you. Have a good day!

Yo it just stopped working…

Onbutton

function onClicked()


		workspace.Alarms.Subscribe:Play()
		for i, Part in pairs(workspace.Lights:GetChildren()) do
			if Part.Name == "Part" and Part:FindFirstChild'Part' then
				Part.Part.Color = Color3.fromRGB(0, 0, 0)
				Part.Part.SurfaceLight.Color = Color3.fromRGB(255, 0, 0)
			end
		end
	end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

OffButton

function onClicked()

		workspace.Alarms.Subscribe:Play()
		for i, Part in pairs(workspace.Lights:GetChildren()) do
			if Part.Name == "Part" and Part:FindFirstChild'Part' then
				Part.Part.Color = Color3.fromRGB(0, 0, 0)
				Part.Part.SurfaceLight.Color = Color3.fromRGB(255, 0, 0)
			end
		end
	end

	script.Parent.ClickDetector.MouseClick:connect(onClicked)

What’s not working, is it not changing any parts?

Nope, just playing the song… [I didn’t even touch it]

Ok, can you screenshot the explorer

I was trying to change the variables like “Subscribe” once I did it broke.

Do the parts in the Lights folder have more parts inside of them or do they just have a surfacelight?

Workspace-Lights-Part-SurfaceLight [Yes just surfacelight]

for i, Part in pairs(workspace.Lights:GetChildren()) do
	if Part.Name == "Part" then
		Part.Color = Color3.fromRGB(0, 0, 0)
		Part.SurfaceLight.Color = Color3.fromRGB(255, 0, 0)
	end
end

It’s working thanks, Your a life saver!