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

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

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.

2 comments

0

hmm can i see your script, so I know what you put into it? Makes it easier

0

Done, I hope it helps.

1 answer

✓ Accepted answer

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

1 comment

0

Ya, it seem as though I'll have to. Thanks for your suggestion.

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