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

How do I detect what pattern buttons were pressed?

Asked by 4 years ago

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.

2 answers

Log in to vote
1
Answered by
karlo_tr10 1233 Moderation Voter
4 years ago

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)
Ad
Log in to vote
2
Answered by
b3wz 34
4 years ago

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

0
What would be the location? GamingWithFlight 80 — 4y

Answer this question