Is there any tutorial of mouse.TargetFilter ? (Ignore players)

Hi, I got this problem, I want to ignore all the players to hit the dummy.

I know that I need a folder to ignore in workspace and then just filter the folder but I can’t find any tutorial to understand it well

Hi, can you elaborate further on what your goal is? Do you want to specifically damage the dummy and not the players?

Thanks

1 Like

Are you looking for this…
Mouse | Documentation - Roblox Creator Hub ?

1 Like

Yes, but what I have to do? Create a folder to ignore with all the players inside?

mouse.TargetFilter = workspace.Ignore ?

I want to click the dummy with mouse.Target ignoring a player if there is one

TargetFilter is pretty limited, you won’t be able to use it for ignoring player characters

you want to replicate the mouse hit yourself, using Mouse.UnitRay and
WorldRoot:FindPartOnRayWithIgnoreList

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

local someTestPart = Instance.new("Part")
someTestPart.Size = Vector3.new(1, 1, 1)
someTestPart.Anchored = true
someTestPart.BrickColor = BrickColor.Green()

local ignoreDescendantsTable = {workspace.Dummy} -- add whatever you want to be ignored

function addPartAtHit()
	local mouseUnitRay = mouse.UnitRay
	local ray = Ray.new(mouseUnitRay.Origin, mouseUnitRay.Direction * 1000)
	local part, position = workspace:FindPartOnRayWithIgnoreList(ray, ignoreDescendantsTable)
	local testPartClone = someTestPart:Clone()
	testPartClone.Position = position
	testPartClone.Parent = workspace
end

mouse.Button1Down:Connect(addPartAtHit)
1 Like

Did you look at the example from the wiki (the link that i provided)? To ignore parts or models you would set mouse.TargetFilter to that model or object. Along with that, straight from the wiki:

The descendants of the object are also ignored, so it is possible to ignore multiple objects so long as they are a descendant of the object to which this property is set

So all you would need to do is put the npcs in a model and Set the Target Filter accordingly


And yes as Quoteory said they are limited depending on what you are trying to do, so then using the ray constructor is also an option.

I’ve previously needed to do exactly what the OP is trying to do (ignore player characters), and putting player characters inside of a folder does not work well, it’s very buggy and you start to bob slightly up and down

and even if it did work I still wouldn’t recommend doing it, as it feels very hacky and it could break scripts that have anything do with checking the parent of a character, as it would be a folder now and not workspace

2 Likes

Thank you so much! But I need to ignore all the players not the dummy. So I need a for to put all the players in ignoreDescendantsTable everytime I click?

Yes, use the :GetPlayers() method and put their characters in the ignoreDescendantsTable :

local Players = game:GetService("Players")

local ignoreDescendantsTable = {workspace.Dummy}

 for _, plr in ipairs(Players:GetPlayers()) do
    table.insert(ignoreDescendantsTable, plr.Character)
end

So Using @Quoteory code above that would look something like:


function addPartAtHit()

local ignoreDescendantsTable = {}
     for _, plr in ipairs(Players:GetPlayers()) do
    table.insert(ignoreDescendantsTable, plr.Character)
 end

    local mouseUnitRay = mouse.UnitRay
	local ray = Ray.new(mouseUnitRay.Origin, mouseUnitRay.Direction * 1000)
	local part, position = workspace:FindPartOnRayWithIgnoreList(ray, ignoreDescendantsTable)
	local testPartClone = someTestPart:Clone()
	testPartClone.Position = position
	testPartClone.Parent = workspace
end

Or if you wanted to you can use PlayerAdded and add players that way instead of doing it every time addPartAtHit is called.

5 Likes