I am trying to script the weapon so that it could damage and knockback the enemy when it is behind a non-cancollide wall. However it is not knocking back nor damaging the enemy when it is behind a non-cancollide wall. There are no errors related to it popping up in the output.

Here is the code.

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

for _, v in pairs(mouse.Target.Parent:GetChildren()) do
	if v:IsA("BasePart") then
		if v.CanCollide == false then
			mouse.TargetFilter = v
		end
	end
end

So how do I make this work? I also tried mouse.Target:GetChildren() as well but nope.

2 comments

0

TargetFilter is defined as a property which: Determines an object (and its descendants) to be ignored when determining Mouse.Hit and Mouse.Target. Try changing line 6 to mouse.TargetFilter = v.Parent, since you're already using :GetChildren()

0

It still does not work :/. It now also detects enemies behind cancollide walls for some reason