local gen = { gen1 = game.Workspace.GeneratorOne.Screen.ClickDetector, gen2 = game.Workspace.GeneratorTwo.Screen.ClickDetector, gen3 = game.Workspace.GeneratorThree.Screen.ClickDetector, gen4 = game.Workspace.GeneratorFour.Screen.ClickDetector }; local lights = game.Workspace["Light Switch"].Lights:GetChildren() for _, button in pairs(gen) do button.MouseClick:Connect(function() for _, light in pairs(lights) do if light.SpotLight.Range == 0 then print("bob") light.Material = Enum.Material.Plastic else print(tostring(light.SpotLight.Range)) light.Material = Enum.Material.Neon end end end) end
This is because you are only putting the same event in every click detector. Instead, make a separate script and copy it to the click detector. Events in loops is s big no no.
Also that’s the point of a click detector. It runs code on mouse click.
--server script, MAKE SURE ITS DISABLED!! script.Parent.MouseClick:Connect(function(plr) -- code end)
for _, button in pairs(gen) do local clickCode = script.ClickDetectorScript:Clone() clickCode.Parent = button clickCode.Disabled = false -- you were supposed to set it to true manually in properties end