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

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

Asked by
Voltoxus 248 Moderation Voter
10 years ago

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

Log in to vote
2
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

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 )
0
This gives me coordinates how do I get objects? Voltoxus 248 — 10y
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 BlueTaslem 18071 — 10y
Ad
Log in to vote
1
Answered by
joeldes 201 Moderation Voter
6 years ago
Edited 6 years ago

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

Answer this question