Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you make mouse.Hit.p Ignore parts ?

I need to make the mouse ignore the players gun and fake arms in my FPS game i'm making and the mouse.Hit.p is vital to the gun Its used for position the gun up and down on the Y-Axis to point at the mouse and also gets the coordinates of were the bullet will fly too, please help! thanks

Also the script is running in a local script, and is not in a tool i'm using the GetMouse() function

2 answers

✓ Accepted answer

The Hit property of a mouse ignores any descendants of the player's Character.

Sometimes that may not be the best option, in which case you could use raycasting, probably the FindPartOnRayWithIgnoreList method.

It could look like this:

local from = workspace.CurrentCamera.CoordinateFrame.p

local to = mouse.Hit.p

local ignore = { --[[whichever parts you want]] , player.Character }

local ray = Ray.new( from, (to - from).unit * 1000)

local newTarget, newHit = workspace:FindPartOnRayWithIgnoreList(
	ray, ignore )

2 comments

0

This gives me coordinates how do I get objects?

0

newTarget and newHit correspond to the mouse's .Target and .Hit. I don't know how to answer your question in any otherw ay

For anybody looking at this question three years later like me. You can use the following method.


Target Filter

If set, the TargetFilter and its descendants will be ignored when determining which part the mouse is pointing to.

From the Roblox Wiki

Here is a crude example.

-- Get the mouse
local Mouse = game:GetService("Players").LocalPlayer:GetMouse()

-- Make a part
local part = Instance.new("Part", workspace)

Mouse.TargetFilter = part
-- You can also get parts directly from the workspace with "game.Workspace.part" or "workspace.part"

Anyways, you can read up on it a bit here:

Target Filer Documentation

If you liked my answer you have my humble permission to upvote. (just kidding... do what you want!)

And also, for more Roblox answers you can follow me on Twitch and YouTube

This discussion is preserved as it was. New answers, comments, and votes are closed.