Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I link a "Light Switch" and make it turn on more than one light?

I made a light switch that controls only one light, here is the script used:

switch = script.Parent
light = game.Workspace.LIGHT.PointLight


switch.ClickDetector.MouseClick:connect (function()
	if light.Enabled == false then
		light.Enabled = true
		switch.BrickColor = BrickColor.new("Lime green")
		
	elseif light.Enabled == true then
		light.Enabled = false
		switch.BrickColor = BrickColor.new("Really red")
	end	
end)

How do I make more than one light turn on but with only using the one light switch? (I need 6 PointLight blocks to turn on with only one light switch on the wall)

1 answer

✓ Accepted answer

You can put all of the PointLight object parts into a single model and then use a For loop to turn each one on. Here is the For loop that you would need to use:

switch = script.Parent

switch.ClickDetector.MouseClick:connect (function()
	for i, v in pairs(game.Workspace.MODELNAME:GetChildren()) do
		if v.PointLight.Enabled == true then
			v.PointLight.Enabled = false
			switch.BrickColor = BrickColor.new("Really red")
		else
			v.PointLight.Enabled = true
			switch.BrickColor = BrickColor.new("Lime green")
		end
		wait()
	end
end)

3 comments

0

You would place this inside of the switch object that is being clicked. I have edited this multiple times so you may need to refresh the page to see the most recent version.

0

It works! Thank you so much!

0

No problem. It's what the site is for.

This discussion is preserved as it was. New answers, comments, and votes are closed.