How do I make a key combination in order?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    make a key combination that functions things in order
  2. What is the issue? Include screenshots / videos if possible!
    I cant figure out how to involve tick when trying to create a key combination in order
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried using tick, I also looked in dev forum, cant find anything that is what i’m looking for
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

I hope you can understand my problem, i am trying to make it so that you have to press z,x,and c, in order, and you do not have to hold the keys for it to work, and when you press them all in order, it changes walkspeed to 50, and i tried using tick so that whenever you dont press a key for 1 second, the combination restarts.

local char = script.Parent
local hum = char:WaitForChild("Humanoid")
local uis = game:GetService("UserInputService")
local streak = 1
local PreviousPunch = 0
local canSprint = 1

uis.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.Z and canSprint == 1 then
		if tick() - PreviousPunch <= 1 then
			streak = 1
			canSprint = 2
			print("1")
			streak = streak + 1
		else
			canSprint = 1
			print("reset")
			streak = 1
		end
		PreviousPunch = tick()
	end
	if key.KeyCode == Enum.KeyCode.X and canSprint == 2 then
		if tick() - PreviousPunch <= 1 then
			streak = 1
			canSprint = 3
			streak = streak + 1
			print("2")
		else
			canSprint = 1
			print("reset")
			streak = 1
		end
		PreviousPunch = tick()
	end
	if key.KeyCode == Enum.KeyCode.C and canSprint == 4 then
		if tick() - PreviousPunch <= 1 then
			streak = 1
			canSprint = 1
			print("3")
			if streak >= 3 then
				hum.WalkSpeed = 50
				canSprint = 1
				print("finished")
			end
			streak = streak + 1
		else
			print("reset")
			canSprint = 1
			streak = 1
		end
		PreviousPunch = tick()
	end
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like
local Combos = {}
local function SetCombo(Name, Keys, MaxInputGap, Function)
	Combos[Name] = {
		["Keys"] = Keys,
		["MaxInputGap"] = MaxInputGap,
		["Function"] = Function
	}
end


SetCombo("God", {Enum.KeyCode.G, Enum.KeyCode.Zero, Enum.KeyCode.D}, 1, function()
	local Char = game.Players.LocalPlayer.Character
	if Char then
		local Hum = Char:FindFirstChildOfClass("Humanoid")
		if Hum then
			Hum.MaxHealth = math.huge
			Hum.Health = Hum.MaxHealth
		end
	end
end)


SetCombo("Die", {Enum.KeyCode.D, Enum.KeyCode.One, Enum.KeyCode.Three}, 1, function()
	local Char = game.Players.LocalPlayer.Character
	if Char then
		Char:BreakJoints()
	end
end)


SetCombo("zxc", {Enum.KeyCode.Z, Enum.KeyCode.X, Enum.KeyCode.C}, 1, function()
	local Char = game.Players.LocalPlayer.Character
	if Char then
		local Hum = Char:FindFirstChildOfClass("Humanoid")
		if Hum then
			Hum.WalkSpeed = 50
		end
	end
end)


local LastInput = 0
local ComboProgress = 0
local CurrentCombos = {}
local RunService = game:GetService("RunService")
game:GetService("UserInputService").InputEnded:Connect(function(obj)
	if #CurrentCombos > 0 then
		local Progression = false
		for i, v in pairs(CurrentCombos) do
			local Combo = Combos[v]
			if RunService.Stepped:Wait() - LastInput > Combo.MaxInputGap then
				table.remove(CurrentCombos, i)
				continue
			end
			if (#Combo.Keys == ComboProgress+1) then
				if Combo.Keys[ComboProgress+1] == obj.KeyCode then
					coroutine.wrap(function()
						Combo.Function()
					end)()
					ComboProgress = 0
					LastInput = RunService.Stepped:Wait()
					return
				else
					table.remove(CurrentCombos, i)
				end
			else
				if Combo.Keys[ComboProgress+1] == obj.KeyCode then
					Progression = true
					continue
				else
					table.remove(CurrentCombos, i)
				end
			end
		end
		if Progression then
			ComboProgress += 1
		end
	else
		for i,v in pairs(Combos) do
			if v.Keys[1] == obj.KeyCode then
				table.insert(CurrentCombos, i)
				ComboProgress = 1
			end
		end
	end
	LastInput = RunService.Stepped:Wait()		
end)

How would i use 2 keys for the same combo, for example; z z x

Yes and. It doesn’t work I’ve tried it

Works fine, you are doing something wrong…
(Localscript → StarterPlayerScripts)
Combos: (d13, g0d, zzx)
Combos.rbxl (33.5 KB)

oh yeah mb I had it in starterCHARACTERscripts