Help with mouse and its properties

Hello, could someone help me tell how the mouse works and its properties that I show in the following image with some example code, please, I am reading the API from the docs and I do not understand these points :frowning:
Mouse (roblox.com)

code to get mouse:

1. -- From a LocalScript:
2. local Players = game:GetService("Players")
3. local player = Players.LocalPlayer
4. local mouse = Player:GetMouse()

Image:

I would really appreciate if someone could make me understand the properties of the mouse of the image with an example of code or something :frowning:

2 Likes

The Mouse.Hit just returns a Cframe of where its 3d position is compared to the camera. Most guns use this for aiming

The Mouse.Icon will just change the picture of the mouses Icon

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
mouse.Icon = "A decal id I'm pretty sure"

The Mouse.Origin is just the CurrentCamera’s position

The Mouse.Target returns the BasePart that it is pointing at. If the mouse is on the skybox it will return nil, you can you Mouse.TargetFilter to filter out certain parts like raycast

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

mouse.Button1Click:Connect(function()
  local part = mouse.Target
  if part then
    print(part.Name)
  end
end)

Hopefully this helps

1 Like

wow thanks you a lot! :smiley:

i tried it and got an error:

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

mouse.Button1Click:Connect(function()
  local part = mouse.Target
  if part then
    print(part.Name)
  end
end)

image

what’s wrong i did the localscript in StarterCharacterScripts

Here. Let me go through em all.

Mouse.Hit: The mouse CFrame (position) in 3D space. You can convert it to vector by doing Mouse.Hit.Position.

Mouse.Icon: basically the icon of your mouse. It is the cursor image (roblox decal id).

Mouse.Origin: the CFrame of the camera, that’s pointed towards the mouse.

Mouse.Target: Basically the current object the mouse is pointing to.

Mouse.TargetFilter: It basically ignores one instance and it’s descendants, which means when the mouse points on it, the target will either be nil, or the object behind it.

1 Like

It’s Button1Down, not Button1Click.

1 Like

Wow! awesome, thanks guys for the help and your feedback!! thanks you a lot :smiley: :smiley: