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

How would make something happen with multiple keys pressed?

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)

1 comment

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

1 answer

✓ Accepted answer
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.

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