Which is better for detecting/handling mouse actions, UserInputService or game.Players:GetMouse()?

So, im thinking of scripting something(not really important to the context, so im not really going to tell), and i want to know like the title says, which is better for handling/detecting mouse actions? And if you do tell me what is better, i would like some reasoning on why.

Any help would be appreciated!

1 Like

If i’m correct with UserInputService you can only get the mouse when it’s clicked. Please correct me if I’m wrong.

It really depends on what you’re using it for as mentioned below.

5 Likes

I dont think any of them is necessarily better than the other, it really depends on what you need them for. They both have useful functions, for example GetMouse lets you get the mouse position easily without connecting any sort of event or anything as mentioned above, while the userinputservice let’s you easily get things like the mouse’s delta and provides other useful functions and things

For detecting inputs in general the only real difference is how much functionality the userinputservice has

2 Likes

I use contextactionservice in combination with the mouse api of course

now that i thought of it, youre pretty much right. Heres how i view this. UserInputService is better for handling mouse actions, because it also supports mobile and pretty much all devices, but like you said, player:GetMouse() is better for knowing where the mouse position that its at(except delta, that is returned by UserInputService).

If you’re focusing on cross-platform support, use ContextActionService.
It can bind stuff to keys and inputs, and will also create a mobile button if requested.

Exactly, I try to use UserInputService since Mouse is a much older feature. It’s annoying that the one thing I can’t do with UIS is get the mouse’s position in 3D space, forcing me to use Mouse for just that purpose.

3 Likes

meh im not going to use that because personally, ContextActionService just is utterly confusing to me, and its key pressing job can be done with UserInputService(not sure if its just as well or effective, but its definitely more simple).

The PlayerMouse object has virtually no use anymore. UserInputService can do everything that GetMouse can and more, as can ContextActionService. You should look towards using either of those over GetMouse given limited or deprecated functionality (limited e.g. TargetFilter, deprecated e.g. KeyDown).

1 Like

hmm, but what about mouse.unit, and mouse.ray? how would you get that from userinputservice?

You don’t. You plug the X and Y coordinates into ViewportPointToRay under the CurrentCamera to serve as the basis for a unit raycast (Mouse.Unit), then extend that ray outward (Mouse.Ray).

1 Like