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

Is it possible to filter parts using mouse.Hit.p?

Asked by
Link43758 175
10 years ago

Or, instead of mouse.Hit.p, are there any other methods that can get the mouse's position while filtering out parts?

0
Oh, another note: I want to filter out a local part. Link43758 175 — 10y

1 answer

Log in to vote
0
Answered by 10 years ago

This is quite simple! If you intend on "Local Part" as a part in the character instance, it's VERY easy.

For this, you will use RayCasting in a LocalScript, as well as a function to find if something is a character.

local hit = mouse.Hit.p
local ray = Ray.new(
    game.Players.LocalPlayer.Character.Torso.CFrame.p,
    (game.Players.LocalPlayer.Character.Torso.CFrame.p - hit).unit * 500
)

function FindIfPlayer(part)
    if part ~= nil then
        if game.Players:findFirstChild(part.Name) ~= nil then
            return part.Parent --Return the character as the ignore
        end
    end
    return nil
end

local partHit, Position = workspace:findPartOnRay(ray, FindIfPlayer(partHit))

local MouseHit = Position --Set a new variable of the mouse's hit that ignored characters

Using the above code, it will find parts hit and ignore characters.

Ad

Answer this question