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

How do I make a door that is opened when 5 lights are activated?

I'm trying to make a door that opens when five lights are activated. I don't see what I'm doing wrong. Here is my script:

local DarklightDoor = script.Parent if game.Workspace.ActivationLights.Material == Enum.Material.Neon then Transparency = 1 end

2 comments

0

try a "while loop" ~~~~~~~~~~~~~~~~ local DarklightDoor = script.Parent while true do wait() if workspace.AcvtivationLights.Material == Enum.Material.Neon then Transparency = 1 end end ~~~~~~~~~~~~~~~~~~~~~~

0

Sorry, while loop doesn't work, let me know if you can figure anything else out@

2 answers

You can do this

light1On = false
light2On = false
light3On = false
light4On = false
light5On = false


--However you are going to make them to turn on, goes here

if light1On == true and light2On == true and light3On == true and light4On == true and light5On == true then
-- Code goes here to open the door
end)

4 comments

0

This doesn't work, I just tested it.

0

It doesn't work because all light variables are set to false as default and are never changed. I advice you to learn how to program before making questions which can't be answered without scripting all the code for you.

0

^^^ Agreed, if you can't make a simple value changing script, you require more practice and aren't ready to ask questions without us having to build the whole if not most of the script for you.

0

Well Yes My script doesn't "work" because you haven't turned the variables back on, i can't do everything for you, use your logic, and you will make it!

It's not working because you only check if the door is open once, at the very beginning of the game. What you need to do is send a check whenever a light changes, so the door can react accordingly.

The most efficient way to do this is to send the check whenever your other scripts activate the light (ex. if your script turns the light on when clicked, send the check through the same function). But since you didn't clarify how these lights were activated, we can just check the material itself with GetPropertyChangedSignal("Material").


--set up variables for the objects
local ActivationLights = game.Workspace.ActivationLights
local DarklightDoor = script.Parent

--handles updating the door to open/closed depending on the lights' material
local function updateDoor()
	if ActivationLights.Material == Enum.Material.Neon then
		DarklightDoor.Transparency = 1
	end
end

--connects the lights' material changing to the door's update
ActivationLights:GetPropertyChangedSignal("Material"):Connect(updateDoor)

I'm worried that ActivationLights isn't what you think it is since there should be 5 different lights you're checking. If ActivationLights is a Group/Model with the 5 lights inside it, you must use this code instead:


--set up variables for the objects
local ActivationLights = game.Workspace.ActivationLights
local DarklightDoor = script.Parent

--handles updating the door to open/closed depending on the lights' material
local function updateDoor()
	
	--loops through all the lights and checks their materials
	--isAllNeon is default to true, but turns false after seeing one light if it sees a light that's not neon
	local isAllNeon = true
	for _,light in pairs(ActivationLights:GetChildren()) do
		if light.Material ~= Enum.Material.Neon then
			isAllNeon = false
			break
		end
	end
	
	--checks if all the lights were neon
	if isAllNeon then
		--change the door to OPEN
		DarklightDoor.Transparency = 1
	else
		--change the door to CLOSED
		DarklightDoor.Transparency = 0
	end

end

--connects every lights' material changing to the door's update
for _,light in pairs(ActivationLights:GetChildren()) do
	light:GetPropertyChangedSignal("Material"):Connect(updateDoor)
end

1 comment

0

I didn't want it to close, so I removed the closed option, but when I had it it still didn't work. Please help!

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