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

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

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

1 comment

0

Oh, another note: I want to filter out a local part.

1 answer

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.

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