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
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)
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