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

UserInputService is not detecting mouse input?

Asked by 4 years ago

I've been trying to make a dragger which when you hold it moves it. All the positioning works but I have a problem with UserInputService. When trying to check if the button that was pressed was left mouse click, it did not register the click. I've checked it by doing this

inputservice.InputBegan:Connect(function(t) -- inputservice is a variable to UserInputService
    print(t.KeyCode)
end)

and it prints out Enum.KeyCode.Unknown when clicking. Any potential fix?

2 answers

Log in to vote
1
Answered by
noammao 294 Moderation Voter
4 years ago
local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function()
local Pressed = UserInputService:IsMouseButtonPressed(Enum.UserInputType.MouseButton1)
    if Pressed then
    print("Pressed")
    end
end)
Ad
Log in to vote
0
Answered by
VitroxVox 884 Moderation Voter
4 years ago

Hello well i might know the problem but i'll show you the code without explaining so try this:

local UserInputService = game:GetService("UserInputService")

UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if input.UserInputType == Enum.UserInputType.Keyboard then
        local keyPressed = input.KeyCode
        print(keyPressed)
    end
end)

Answer this question