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
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)
or simply just use raycasting.
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
Okay, thanks for the information!