Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Qu_xtty -8
4 years ago

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

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 ~~~~~~~~~~~~~~~~~~~~~~ ScriptsALot 91 — 4y
0
Sorry, while loop doesn't work, let me know if you can figure anything else out@ Qu_xtty -8 — 4y

2 answers

Log in to vote
0
Answered by
Borrahh 265 Moderation Voter
4 years ago

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)
0
This doesn't work, I just tested it. Qu_xtty -8 — 4y
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. User#27525 1 — 4y
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. HSlightsteel 14 — 4y
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! Borrahh 265 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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
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! Qu_xtty -8 — 4y

Answer this question