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

How to turn off multiple lights at once?

I want to blink then turn off all the lights when you touch a part on the floor.

This is what the workspace looks like for a better understanding

Model
	Script
	Lights
		Part
			SpotLight
		Part
			SpotLight
	Hit (The part that you touch)

This is the script to turn the lights off

local part = script.Parent
local Light = script.Parent.Lights:GetDescendants("SpotLight")
local hit = script.Parent.Hit




local function onPartTouched(hit)
	hit.CanTouch = false
	Light.Enabled = false
	wait(.2)
	Light.Enabled = true
	wait(.1)
	Light.Enabled = false
	wait(.2)
	Light.Enabled = true
	wait(.2)
	Light.Enabled = false
end

hit.Touched:Connect(onPartTouched)

1 comment

0

yeah, its better to use a for loop in the case

1 answer

Use a 'for loop'.

This function turns all lights on/off at once.

local function lights(bool)
	
	for _, v in pairs(Light) do
		
		v.Enabled = bool
	end
end

Then, you can call this function in onPartTouched() :

lights(false)
wait(.2)
lights(true)
wait(.1)
lights(false)
wait(.2)
lights(true)
wait(.2)
lights(false)

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