I created a keybind sequence script, feel free to use it. (Place in game.StarterPack
)
Settings
Local Variable
sequence: table - The sequence of Enum.KeyCode.Name’s (lowercase)
Local Variable
callback: function - The function to execute after the sequence is complete
Attribute
onlyOnce: boolean - If the sequence can only be called once
You can also extend the script by changing the sequence at runtime and calling the newSequence function to rebuild the sequence.
Source (GitHub isn't necessary for this)
--// CONFIG \\--
local sequence = {'up', 'down', 'left', 'right'}
local callback = function()
-- do something
print("Finished!")
end
--// CODE \\--
local newTbl = {}
local function newSequence()
newTbl = {}
for k, v in ipairs(sequence) do
newTbl[k] = {
['Key'] = v,
['IsDone'] = false
}
end
end
local UIS = game:GetService("UserInputService")
newSequence()
UIS.InputBegan:Connect(function(input)
if #newTbl == 0 then return end
local currentKey, currentIndex
for k, v in pairs(newTbl) do
if v['IsDone'] == false then
currentKey = v['Key']
currentIndex = k
break
end
end
if string.lower(input.KeyCode.Name) == currentKey then
newTbl[currentIndex]['IsDone'] = true
else
for k, _ in pairs(newTbl) do
newTbl[k]['IsDone'] = false
end
end
for _, v in pairs(newTbl) do
if v['IsDone'] == false then return end
end
if script:GetAttribute("workOnce") then
newTbl = {}
end
callback()
end)
Have fun!