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

Is UIS for mouse events better than using player:GetMouse()?

Asked by 6 years ago

I was told a while ago, player:GetMouse() was going to be deprecated and to use UIS for now on. Is this a valid statement or should I use either one depending on the project?

1
`KeyDown` and `KeyUp` are deprecated, so the `UserInputService` should be used instead. TheeDeathCaster 2368 — 6y
0
:GetMouse() isnt depreacted yet, andd tbh i would predfer :GetMouse() since its quicker to write xd and i dont see why one of these two being better than the other since all they do is return the mouse starmaq 1290 — 6y
0
@starmaq UserInputService has much more functionality than the Mouse class (an example: the answer below). ContextActionService should be used more since you can bind functions for mobile buttons, which the Mouse class, again, cannot do. saSlol2436 716 — 6y

1 answer

Log in to vote
1
Answered by
Miniller 562 Moderation Voter
6 years ago
Edited 6 years ago

Both works, I recommend UserInputService

Example for UserInputService - from this website

1local UserInputService = game:GetService("UserInputService")
2UserInputService.InputBegan:Connect(function(input, gameProcessed)
3    if input.UserInputType == Enum.UserInputType.MouseButton1 then
4        print("The left mouse button has been pressed down at",input.Position)
5    end
6end)

(Needs to be a LocalScript)

Example for player:GetMouse() - from this website

1local Player = game.Players.LocalPlayer
2local Mouse = Player:GetMouse()
3Mouse.Button1Down:Connect(function()
4    print("Button 1 is down")
5end)

(Needs to be a LocalScript too)

As you can see, with UIS you can even get the position where player clicked, and I don't think you can do that with GetMouse().

Hope this helps!

Ad

Answer this question