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

How would make something happen with multiple keys pressed?

Asked by 10 years ago

I was wonder how i would get something to happen when 2 keys are pressed here is what i have tried:

game.Players.LocalPlayer:GetMouse().KeyDown:connect(function(key) if key:byte() == 32 then if string.lower(key) == "e" then print("well done or fired") end

    end
end)
0
You could create two global booleans that would become true once someone hit the buttons. Then have a conditional statement that checks to see if both those booleans are true Necrorave 560 — 10y

1 answer

Log in to vote
2
Answered by
Sparker22 190
10 years ago
Button1Pressed = false
Button2Pressed = false

Mouse = game.Players.LocalPlayer:GetMouse()
Mouse.KeyDown:connect(function(Key)
    if Key == "g" then
        Button1Pressed = true
    elseif Key == "h" then
        Button2Pressed = true
    end
    print(Button1Pressed,Button2Pressed)
end)

Mouse.KeyUp:connect(function(Key)
    if Key == "g" then
        Button1Pressed = false
    elseif Key == "h" then
        Button2Pressed = false
    end
    print(Button1Pressed,Button2Pressed)
end)

This code sets it up where if two keys are pressed then both booleans return true. You can simply make a conditional to check for them.

Ad

Answer this question