I want to detect what pattern buttons were pressed. Like if the player pressed part1 first, and then part3, and then part2, and lastly part 4. Then, if they pressed part1 first, part2 second, part3 third, part4 last a part would turn transparent.
✓ ANSWER ACCEPTED
How do I detect what pattern buttons were pressed?
2 answers
✓ Accepted answer
b3wz's idea is good, this is mine:
local Player = game.Players.LocalPlayer
local Door = game.Workspace.Door
local Parts = {
["Part1"] = 1;
["Part2"] = 2;
["Part3"] = 3;
}
local Part1 = game.Workspace.Part1
local Part2 = game.Workspace.Part2
local Part3 = game.Workspace.Part3
local num = 0
Part1.ClickDetector.MouseClick:Connect(function()
local target = num+1
if Parts["Part1"] == target then
num = num+1
else
num = 0
end
end)
Part2.ClickDetector.MouseClick:Connect(function()
local target = num+1
if Parts["Part2"] == target then
num = num+1
else
num = 0
end
end)
Part3.ClickDetector.MouseClick:Connect(function()
local target = num+1
if Parts["Part3"] == target then
num = 0
Door.Transparency = 1
Door.CanCollide = false
else
num = 0
end
end)
This is an idea on how you can do it:
local Pressed = {}
-- when you listen to buttons being pressed do something like this maybe
if #Pressed > 4 then
table.insert(Pressed, button.Name)
else
if Pressed[1] == "Button1" and Pressed[2] == "Button2" and Pressed[3] == "Button3" and Pressed[4] == "Button4" then
-- make part transparent
end
Pressed = {}
end
Might not be the best way to do it but was the first idea that came to my head
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
What would be the location?