Key sequence (im tweaking)

hello im trying to make a key sequence, and im fr tweaking, if i could, i would start swearing fr, help.

3 Likes

i saw that, what i mean by key, is input key

1 Like

You’re trying to recognize a pattern of keys pressed then, something like a Konami Code deal?

1 Like

yeah, more like oh, i press the ult key (G) and then i have to do a key sequence to do a especial attack, how amazing woowww, but im having a lot of issues of understanding where i even go, like how i script or understanding this

1 Like

Oh gotcha, I can write up a sample script of something that can work for you. Give me a moment to write something simple for you to write onto, along with a simple explanation with it.

i did, find a free source key sequence, but i have a problem, needs to have a table of wich key you have to press, and in my baseplate, you have ability and fighting style, pretty much the same, but different controls, now the thing is that in the server storage there some modules scripts and inside of those modules script there tables, now how i pass a server side table into this free source keysequence and put it there, cuz there wanna be a lot of combinations

alr alr? but see the comment i reply to, to understand well the situation

i can show the free source script, but i still dont understand it well, let me open the roblox studio

Heres something I believe can work, not that advanced in UserInputService functions but I would recommend looking on the dev forum for a similar topic to get an accurate answer.

local UserInputService = game:GetService("UserInputService")

local Combo1 = {"G", "Z", "W"}
local Combo1Bool = true
local Combo1Active = false

local function OnInputBegan(Input, Processed)
	if Processed then return end
	if not table.find(Combo1, Input.Keycode.Name) then 
		Combo1Bool = false
	-- if not table.find(Combo2, Input.Keycode.Name) then etc,etc...
	
	local InputObj in pairs(Input) do -- To find out what combo is being used.
		if Combo1Bool == true  and Combo1Active == false then
			table.remove(Combo1, table.find(Combo1, Input.KeyCode.Name)) 
		-- elseif Combo2Bool == true then etc, etc..
	end
	
	-- Now write down what you want to happen after a combo is done!
	if #Combo1 == 0 and Combo1Active == false then -- Just making sure it only activates when cooldown is over.
		Combo1Active = true
		
		-- Enter your function or thing you want to happen after Combo1 is done.
		
		task.wait(0) -- Set the time you want, this will delay the Combo from being started again.
		Combo1 = {'G','Z','W'} -- Setting our Combo1 back since it was deleted.
		Combo1Active = false
	-- elseif #Combo2 == 0 then etc, etc...
	end
end

UserInputService.InputBegan:Connect(OnInputBegan)

I would check with other users about optimizing this if needed. I beleive it does need some optimizations.

After posting this I just realized how scuffed the code is.

1 Like

yah, i was wanna send the free source code that i found, but here a question

if i have this table (sequence, one)


local sequence = {'t', 'j', 'h', 'g'}
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)

and then i just want to use these tables

module.Settings = {
	["Ult_Combinations"] = {-- these one
		["Mega_Punch"] = {
			'e',
			'e',
			'e',
			'e',
		};
		["Mega_Slam"] = {
			'w',
			'w',
			'w',
			'w',
		}
	}
}

how i pass these tables through a function, as arguments, from server side and then client??, that the one im thinking of, that the part i dont undertstand tho

Here’s a simpler version:

local ContextActionService = game:GetService("ContextActionService")

local inputs = {
	Enum.KeyCode.Z,
	Enum.KeyCode.X,
	Enum.KeyCode.C,
	Enum.KeyCode.F,
	Enum.KeyCode.B,
}

local ults = {
	ZXC = function() print("ZXC activated") end,
	FB = function() print("FB activated") end,
}

local sequence = ""

local t = 0

local function callback(_, state: Enum.UserInputState, input: InputObject)
	if state ~= Enum.UserInputState.Begin then return end
	-- this will make it so if you spam the keys they go back to normal after a while
	if os.clock() - t >= 1 then
		sequence = ""
	end
	sequence = sequence .. input.KeyCode.Name
	if ults[sequence] then
		ults[sequence](); sequence = ""
	end
	t = os.clock()
end

ContextActionService:BindAction("combo", callback, false, table.unpack(inputs))
2 Likes

To get information from a Module Script, require it inside of your script and gather the info from there.

Example: – as put from the code you sent.

local ComboModule = require(game:GetService("ReplicatedStorage"):FindFirstChild("Module") -- Replace 'Module' with your modules name.

local Ult_Combos = ComboModule.Settings["Ult_Combinations"]
local sequence = Ult_Combos["Mega_Punch"] -- Replace Sequence with the desired Combo

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)
1 Like

btw, the module is from server, cant do a require, and the module script is wanna be “different”, each time, what i mean by that is wanna be differents modules scripts for each ability, i mean i can make some ideas with having a table from ReplicatedStorage, and checking if you have the ability for each key sequence, but i feel like that could bring a lot of issues, especially if idk, can be exploited?, or made in other way

and i think this give me some ideas tho, like is simplier yea, but i could think some ideas

now that i think of it guys, i feel like the idea of having a table on ReplicatedStorage, can coming more out, but i dont know i still feel like can be very exploiteble, what yall think?

Cool. I added a reset timer because the way it was before you could spam the keys and it would mess the sequence, the timer now will reset the sequence if you don’t press anything for longer than 0.99 seconds, which makes it great i think.

yea, but still there the question that i made, what do you think of it?

The way people used to do it is by sending each letter of the combo to the server and then the server put the pieces together.

-- client (the loop is just an example)
for i = 1, 3 do
     remote:FireServer(randomKey[i])
end
local keys = {}
remote.OnServerEvent:Connect(function(player, key)
      keys[player] = keys[player] .. key

      if keys[player] == "XCF" then
            -- server knows what's up now
      end
end)

ok ok, look, thanks, and thanks @chicknsandwichs , but is very late where i live, and i have to do basicly work, im wanna sleep and tomorrow i wanna updated what i ended up with alright guys?,
and thanks guys like fr, you really help me here fr