Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would i make a combo system using ContextActionService?[]

contextActionService = game:GetService("ContextActionService")
local mobilebutton = contextActionService:BindAction("KeyX",KeyX,true,"H",Enum.KeyCode.ButtonY)
contextActionService:SetPosition("KeyX",UDim2.new(0.72,-25,0.30,-25))
contextActionService:SetTitle("KeyX","X")

Im Not sure how i would fire a function to make it do a combo like if you press Z+X+C then print the combo you did.

2 comments

1

I would highly suggest UserInputService instead. In that, you can use IsKeyDown and I am going to send a tutorial as answer very soon, but still, here's the link: https://wiki.roblox.com/index.php?title=API:Class/UserInputService/IsKeyDown PLEASE UPVOTE THANKS <3

0

Oh and also if you want something like, first Z, then release Z, then press X etc. I'll write for that too. PLEASE UPVOTE THANKS <3

1 answer

I would highly suggest UserInputService instead.

Now, you probably want it in one of those two ways:

  1. Pressing all buttons together

For this, you can use IsKeyDown easily. Here's a tutorial:

local UIS = game:GetService("UserInputService")

function onKeyPress(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.Z then
		if UIS:IsKeyDown(Enum.KeyCode.X) and UIS:IsKeyDown(Enum.KeyCode.C) then
			--The code
		end
	elseif inputObject.KeyCode == Enum.KeyCode.X then
		if UIS:IsKeyDown(Enum.KeyCode.Z) and UIS:IsKeyDown(Enum.KeyCode.C) then
			--Same code above
		end
	elseif inputObject.KeyCode == Enum.KeyCode.C then
		if UIS:IsKeyDown(Enum.KeyCode.X) and UIS:IsKeyDown(Enum.KeyCode.Z) then
			--Totally same code above
		end
	end
end
 
UIS.InputBegan:connect(onKeyPress)
  1. Pressing in an order

For this, you can use tick() or os.time() to calculate time passed between button presses. Here's a tutorial:

local PassedTimeZ = 0
local PassedTimeX = 0
local MaxTime = 0.5

function onKeyPress(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.Z then
		PassedTimeZ = tick()
	elseif inputObject.KeyCode == Enum.KeyCode.X then
		if PassedTimeZ + MaxTime > tick() then
			PassedTimeX = tick()
		end
	elseif inputObject.KeyCode == Enum.KeyCode.C then
		if PassedTimeX + MaxTime > tick() then
			--The Code
		end
	end
end

IF HELPED, PLEASE UPVOTE AND ACCEPT AS ANSWER THANKS <3 :3

This discussion is preserved as it was. New answers, comments, and votes are closed.