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

UserInputService problem when "inputting" a mouse button, any fix/alternative?

Asked by 5 years ago
Edited 5 years ago

So my problem is this: When a mouse button is pressed and recorded by way of "UserInputService", it's KeyCode is returns as "Enum.KeyCode.Unknown".

Now, it returning that whenever, say, right mouse button is clicked is fine, the problem is that it returns that for any/all mouse buttons!

So, is there a way to properly return the KeyCode for mouse buttons with "UserInputService"? If not, what's the best alternative way to get the mouse button clicked? (preferably in Enum.KeyCode format)

Here's some code:

--Made in Local script in StarterGui.
local Input_Service =game:GetService("UserInputService")

Input_Service.InputBegan:Connect(function(input)
    print(input.KeyCode)--When you press any mouse button, you get "Unknown".
end)

I hope this helps,

Thanks.

0
hmm can i see your script, so I know what you put into it? Makes it easier Clasterboy 72 — 5y
0
Done, I hope it helps. mbramblet 80 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

I am not aware of any keycode for mousebutton1, which explains why a mouse click returns an unknown keycode.

Why can’t you use the MouseButton1Down event?

local mouse = game.Players.LocalPlayer:GetMouse()
function click()
print (“yes”)
end
mouse.MouseButton1Down:Connect(click)

Getting mouse adds a ton of functionality since you can Mouse.Target and check if a player is clicking a magic part

I wrote this on my phone lol

0
Ya, it seem as though I'll have to. Thanks for your suggestion. mbramblet 80 — 5y
Ad

Answer this question