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

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

Asked by 6 years ago
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.

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 superalp1111 662 — 6y
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 superalp1111 662 — 6y

1 answer

Log in to vote
-1
Answered by 6 years ago

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)

2) 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

Ad

Answer this question