Still have questions? Join our Discord server and get real time help.
Log in to vote

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

Asked by 2 months 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?

`KeyDown` and `KeyUp` are deprecated, so the `UserInputService` should be used instead. TheeDeathCaster 2211 — 2mo
: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 566 — 2mo
@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 674 — 2mo

1 answer

Log in to vote
Answered by
Miniller 331 Moderation Voter
2 months ago
Edited 2 months ago

Both works, I recommend UserInputService

Example for UserInputService - from this website

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

(Needs to be a LocalScript)

Example for player:GetMouse() - from this website

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
    print("Button 1 is down")

(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!


Answer this question