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 make a button effect multiple objects?

I am trying to make a light switch that can affect many lights and have a wait period of .5 seconds in between it, but the scripts that I try don't work. I've tried different names of the parts and having those inside the script, but it only effects one of the lights. So, here's the script that can actually do something to the light, but only to one.

Also, I am a noob at scripting, please go easy on me!

function onClicked(plyr)
	v = script.Parent.Value
	if v.Value == false then
		v.Value = true
 game:GetService("Workspace").Light.Material = Enum.Material.Neon		
		workspace.Light.BrickColor = BrickColor.new("Fossil")
		script.Parent.BrickColor = BrickColor.new("Bright red")
		workspace.Light.SurfaceLight.Enabled = true
	elseif v.Value == true then
		v.Value = false
 game:GetService("Workspace").Light.Material = Enum.Material.Glass
		workspace.Light.BrickColor = BrickColor.new("Black")
		script.Parent.BrickColor = BrickColor.new("Bright red")
		workspace.Light.SurfaceLight.Enabled = false
		wait(1.05)
	end
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)

1 answer

✓ Accepted answer

You can put all the lights into a folder called Lights in workspace and try something like this:

script.Parent.ClickDetector.MouseClick:Connect(function()
	if script.Parent.Value.Value == false then
		script.Parent.Value.Value = true
		for _,v in pairs(workspace.Lights:GetChildren()) do
			if v:IsA("BasePart") then
				v.Material = Enum.Material.Neon
				v.BrickColor = BrickColor.new("Fossil")
				v.SurfaceLight.Enabled = true
			end
		end
	else
		script.Parent.Value.Value = false
		for _,v in pairs(workspace.Lights:GetChildren()) do
			if v:IsA("BasePart") then
				v.Material = Enum.Material.Glass
				v.BrickColor = BrickColor.new("Black")
				v.SurfaceLight.Enabled = false
			end
		end
	end
end)

1 comment

0

OMG IT WORKS! Thanks so much!

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