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

Is there an InputBegan:Connect for only mouse button 1 clicks?

Asked by 2 years ago

I'm trying to use the user input service to detect when the player has made a left click, this is the code that im using:

local function CheckInput()
    if (UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1)) then
        --blah blah blah
    end
end

UserInputService.InputBegan:Connect(CheckInput)

This works fine with one problem; if the player holds down left click, ANY input on the keyboard will trigger the function. Is there any way to connect to an event for only mouse button 1 clicks? Or just any workaround in general?

1 answer

Log in to vote
0
Answered by 2 years ago

If you want UserInputService to detect if the left mouse button is clicked, you would use Enum.UserInputType.MouseButton1

For example.

local UIS = game:GetService("UserInputService")

function inputBegan(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        print("Left Mouse Button Clicked!")
        --Do whatever you want here.
    end
end

UIS.InputBegan:Connect(inputBegan)
Ad

Answer this question