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

How do I make a keyboard and mouse input combo?

Asked by 2 years ago

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

Log in to vote
0
Answered by
SuperPuiu 497 Moderation Voter
2 years ago

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)
Ad

Answer this question