Hello, i am trying to make if multiple and in a script. If something and something and multiple things then something happens. The issue is that when i try to put more than 2 and then it’s not working anymore. I’ve tried to figure it out, but i was unable to solve the problem.
I need the script for a buzzer system. If all buzzers are red(material is neon) then a fail sound will play. It will also check while true do if the buzzers are pressed.
-- The script that doesn't work
local Part1 = game.Workspace.Part1
local Part2 = game.Workspace.Part2
local Part3 = game.Workspace.Part3
local Part4 = game.Workspace.Part4
while true do
if Part1.Material == "Neon" and Part2.Material == "Neon" and Part3.Material == "Neon" and Part4.Material == "Neon" then
script.Parent.Sound:Play() -- All buzzers are pressed. It will play a fail sound
end
Not sure if you just didn’t copy the whole thing, but you don’t have a task.wait() in the loop so it’s probably just timing out. When you add it, make sure it’s not in the if statement.
local Part1 = game.Workspace.Part1
local Part2 = game.Workspace.Part2
local Part3 = game.Workspace.Part3
local Part4 = game.Workspace.Part4
Part1.Anchored = true
Part2.Anchored = true
Part3.Anchored = true
Part4.Anchored = true
while true do
if Part1.Material == Enum.Material.Neon and Part2.Material == Enum.Material.Neon and Part3.Material == " Enum.Material.Neon and Part4.Material == Enum.Material.Neon then
script.Parent.Sound:Play()
end
local parts = {
game.Workspace.Part1;
game.Workspace.Part2;
game.Workspace.Part3;
game.Workspace.Part4;
}
while true do
for i,part in pairs(parts) do
part.Anchored = true
if part.Material == Enum.Material.Neon then
script.Parent.Sound:Play()
end
end
task.wait()
end