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

How would I make a script activated by multiple keydowns?

Asked by 9 years ago

Like if I hit r and f it would

print("You pressed R and F") -- Example

1 answer

Log in to vote
1
Answered by
RedCombee 585 Moderation Voter
9 years ago

I believe that you would simply need something to make sure that the user has both keys down before one is lifted. To do this, I would use KeyDown and KeyUp.

Note - Code is not tested.

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
rPressed = false
fPressed = false

mouse.KeyDown:connect(function(key)
    key = key:lower()
    if key == "r" then
        rPressed = true
        if rPressed == true and fPressed == true then
            print("You pressed R and F")
        end
    elseif key == "f" then
        fPressed = true
        if rPressed == true and fPressed == true then
            print("You pressed R and F")
        end
    end
end)

mouse.KeyUp:connect(function(key)
    key = key:lower()
    if key == "r" then
        rPressed = false
    elseif key == "f" then
        fPressed = false
    end
end)
0
Make sure to put this code in a LocalScript as well. RedCombee 585 — 9y
0
I see a error in your code: Line 13; You are attempting to compare 'key' with 'f', but 'f' is not defined, so the script may error and say 'Line 13: Attempt to compare 'key' to 'f' (a nil value)'. :P Ya Silly Billy! TheeDeathCaster 2368 — 9y
0
get rid of line 7 and 22 and put on any line that says 'if key == "q" then' or 'if key == "r" then' instead put 'if string.Lower(key) == "q" then' and 'if string.Lower(key) == "r" then' message me on ROBLOX for the full script. raystriker6707 30 — 9y
Ad

Answer this question