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

How do I make a keyboard and mouse input combo?

What I would like to do is so if I'm holding the "E" key down, it will allow me to print "hello" if I click. It doesn't work at all.

-- Variables
local plr = game:GetService("Players").LocalPlayer
local uis = game:GetService("UserInputService")

-- Main function
uis.InputBegan:Connect(function(input, gameProcessedEvent)
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.E then
			if input.UserInputType == Enum.UserInputType.MouseButton1 then
				print("hello")
			end
		end
	end
end)


1 answer

Well, I think you can use Mouse from Player instance for mouse combo:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local UIS = game:GetService("UserInputService")
local isHeld = false

Mouse.Button1Down:Connect(function()
     isHeld = true
end)

UIS.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.E then
            if isHeld == true then
            print("e")
             end
      end
end)

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