Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How would I make a script activated by multiple keydowns?

Like if I hit r and f it would

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

1 answer

✓ Accepted answer

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)

3 comments

0

Make sure to put this code in a LocalScript as well.

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!

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.