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

Is there a way to hold down 2 keys at once to perform an action?

Asked by 8 years ago

I've used if key == "q" and "w" then --so on and so on but it doesn't work. Is there a way to work it?

2 answers

Log in to vote
0
Answered by
Nickoakz 231 Moderation Voter
8 years ago

Not tested, please post output errors ^.^

local PlayersService = game.Players
local MyMouse = PlayersService.localPlayer:GetMouse()
local client={}

function keyDown(key)
    if client[key]~=nil and client[key]==true then --Make sure if its not nill, and that the key is pressed down.
        return true --Return true!
    end
    return false --The key was not found or is not true, then return false.
end 

function Check()
    if keyDown("q") and keyDown("w") then --Check the key through the functions.
        print("yaaay") --Both q and w are down!
    end
end 

MyMouse.KeyDown:connect(function(key)  --Key is pressed down
    client[key]=true --When that specific key is down, log it/make it under the client table.
    Check() --Do a check to see if both keys are down.
end)
MyMouse.KeyUp:connect(function(key) --Key is released
    client[key]=false --When that key is released, restore the log back to false.
end)
0
Thank you it works!!! zekrom6810 15 — 8y
Ad
Log in to vote
-3
Answered by 8 years ago

Use two different LocalScripts and put in StarterPack and it will work.

1st script:

local PlayersService = game.Players
local MyMouse = PlayersService.localPlayer:GetMouse()

MyMouse.KeyDown:connect(function(key) 
    if string.lower(key) == 'w' then
        print("w") -- put code
    end
end)

2nd script:

local PlayersService = game.Players
local MyMouse = PlayersService.localPlayer:GetMouse()

MyMouse.KeyDown:connect(function(key) 
    if string.lower(key) == 'q' then
        print("q") -- put code
    end
end)

Now, when you press 'q' and 'w', it will fire at the same time. Replace "print()" with your code

0
I don't want that. Its something different. I want something like if you use "q" AND "e" at the same time, then an action will occur. zekrom6810 15 — 8y
0
My bad laughablehaha 494 — 8y
0
I edited it. laughablehaha 494 — 8y

Answer this question