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?
✓ ANSWER ACCEPTED
Is there a way to hold down 2 keys at once to perform an action?
2 answers
✓ Accepted answer
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)
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
3 comments
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.
0
My bad
0
I edited it.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Thank you it works!!!