How to make a full click with your mouse

How to make a full click with your MOUSE


You probably heard of the player’s mouse. It’s very simple to get, but it can only be accessed in a local script:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

How do you want to check if a player clicks on their mouse? You’d want to do something like this:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.Button1Down:Connect(function()
    print("clicked")
end)

You might’ve noticed that this function can only fire as soon as you click down. What about if you fully do a click, by going down then back up? Some people do want this, so let’s try to provide a solution to this problem.


—STEP 1—

Let’s begin by saving the mouse’s position as soon as you click down:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.Button1Down:Connect(function()
    local positionA = Vector2.new(mouse.X,mouse.Y)
end)

—STEP 2—

Next, let’s actually wait for the player to lift their mouse click back up, which usually has to signal a full click:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.Button1Down:Connect(function()
    local positionA = Vector2.new(mouse.X,mouse.Y)
    mouse.Button1Up:Wait()
end)

—STEP 3—

Now, let’s get the mouse’s position again, then compare those two to see if they are similar:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.Button1Down:Connect(function()
    local positionA = Vector2.new(mouse.X,mouse.Y)
    mouse.Button1Up:Wait()
    local positionB = Vector2.new(mouse.X,mouse.Y)
    if positionA ~= position B then return end
    print("full click detected")
end)

So now it gets the position when you lift your mouse up, and checks if position A and B are similar, which indicates a full click, if it does, the code continues, and if not, it’ll stop the script.


—CONCLUSION—

So now we did it. It was a pretty short tutorial but I just wanted to give a quick solution to anyone who does encounter this problem, so I hope this works out for you.

The only downside is that the script won’t treat it as a full click if you click and your mouse moves even one pixel.

I will be updating this, since I was on a rush, so stay tuned if you get notified about this.

So yeah, there you have it. Bye!


-DiamondDrencher1

Remove the space between the n and B so it will work properly

you could also do this :+1:

game:GetService("UserInputService").InputEnded:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        print("clicked")
    end
end)
9 Likes

I would Recommend you use UserInputSerivce instead of :GetMouse() as it was superceded by UserInputService.

Also this tutorial doesnt really explain much, its just a very vague explanation not really telling the user what the code actually does or why we wrote it in the first place.

1 Like

Btw, This wouldnt work since humans arent perfect and will move the mouse by a TINY bit no matter what. ur gonna need to check the magnitude

1 Like

Right, especially on phone and tablet, it is impossible to touch and untouch in the exact same spot.

1 Like

I said I was going to update this later. There’ll be much more explanation and tweaks. I don’t have the time to do it right now.

1 Like