FindPartOnRayWithIgnoreList

I have been trying to script a gun. I wanted this gun to have bullet holes, but I have run into a problem. What I believe is happening is that the ray cast is hitting the bullet holes. Watch the video to see the problem. I also have a snippet of my code below. It is not missing an end, I’m just not showing it, all the variables are defined, and this part of the code is a part of a shoot event for the gun. For any more info, just ask me!

		local RayCast = Ray.new(FromP, (ToP-FromP).unit*100)
		local Part, Position, Normal = game.Workspace:FindPartOnRayWithIgnoreList(RayCast, {plr.Character, tool, game.Workspace.BulletHoles}, false, true)
		if Part then
			local Hum = Part.Parent:FindFirstChild("Humanoid")
			local Dist = (ToP-FromP).magnitude
			if Hum and Dist < 300 then
				Hum:TakeDamage(7)
			end
			
			local Lazer = Instance.new("Part")
			Lazer.Parent = game.Workspace
			Lazer.Anchored = true
			Lazer.CanCollide = false
			Lazer.Size = Vector3.new(0.1,0.1,Dist)
			Lazer.CFrame = CFrame.new(FromP,Position)*CFrame.new(0,0,-Dist/2)
			print(Part.Parent.Name.." WAS SHOT")
			if not Part:FindFirstAncestor("BulletHoles") then
				local Hole = game.ReplicatedStorage.BulletHole:Clone()
				Hole.Parent = game.Workspace.BulletHoles
				Hole.Position = ToP
				Hole.Name = "BulletHole"
				Hole.CFrame = CFrame.new(Hole.Position, Hole.Position+Normal)
				local Weld = Instance.new("Weld")
				Weld.Part0 = Part
				Weld.Part1 = Hole
				Weld.C0 = Part.CFrame:Inverse()
				Weld.C1 = Hole.CFrame:Inverse()
				Weld.Parent = Hole
				game.Debris:AddItem(Hole,5)
			end

also, the Print statement has been printing Workspace every time, even though it seems to be hitting the bullet holes which are parented to the BulletHoles folder

the raycast does ignore it, but the mouse doesn’t, to fix that you should put mouse.TargetFilter =workspace.BulletHoles in your code, what Mouse.TargetFilter does is ignore whatever you put there

i dont speak English very well lol

It didn’t help… Just to be sure, this is the code I need to run to set the target filter:

local Mouse = game.Players.LocalPlayer:GetMouse()
Mouse.TargetFilter = game.Workspace.BulletHoles -- game.Workspace.BulletHoles is a folder

TargetFilter

I made it so that a bullet hole can’t be within 1.2 studs of another

Hey sorry for the late response, I don’t know if this is still relevant, but for anyone looking for an answer concerning this, baseparts have a property called CanQuery.

Basically, when that property is false, any use of Raycast and Region3 will not be able to detect the part anymore.

Important note: it does require CanCollide to be false too.