How to blacklist mouse.hit.P objects?

How can I blacklist objects for mouse.hit.P to ignore?

Mouse objects have a TargetFilter property, this property is used to determine objects that should be ignored in Hit and Target. This can only store 1 object but will also ignore its descendants, so you could put the objects to ignore in a folder and set the TargetFilter to that folder

1 Like

I have a gun script and I used targetfilter, however its still colliding with something…

local mouse = game.Players.LocalPlayer:GetMouse()

mouse.Button1Down:Connect(function()
	
	script.Parent.Fire:FireServer(mouse.Hit.p)
	
	local BulletHole = game.ReplicatedStorage:WaitForChild("Bullethole"):Clone()

	BulletHole.Parent = workspace
	BulletHole.Position = mouse.Hit.p

	BulletHole.CFrame = CFrame.lookAt(script.Parent.Handle.Position, BulletHole.Position)
	
	mouse.TargetFilter = game.Players.LocalPlayer.Character
	
end)
1 Like

Use RbxMouse module from @EmeraldSlash.
It is using Raycasting to filter objects.

1 Like

or simply just use raycasting.

2 Likes

This line is supposed to be either before the button1down function or before it fires the server.

Can we do a for loop then ignore the object?

Like this:

for i, object in pairs(exampleFolder:GetChildren()) do
    mouse.TargetFilter = object
end

You’re setting the targetfilter after everything else, try putting it as the first line in the Button1Down event

@AridFights1 No, that would only ignore one of hte objects, you can jsut set TargetFIlter to exampleFolder and it would work since it would ignore descendants

1 Like

Okay, thanks for the information!

1 Like