RayCast not ignorning RayCastParams Filter Objects

I have a Gun that is using workspace:raycast for hit detection, and using RaycastParams to ignore certain parts (descendants of the gun, and descendants of your LocalPlayer.Character).

For some reason, the RayCast result isn’t ignoring the filtered objects.

Relevant Code:

local RayCastFilter1 = RaycastParams.new()
RayCastFilter1.FilterType = Enum.RaycastFilterType.Blacklist;
RayCastFilter1.FilterDescendantsInstances = {LocalPlayer.Character;};
local RayCastFilter2 = RaycastParams.new()
RayCastFilter2.FilterType = Enum.RaycastFilterType.Blacklist;
RayCastFilter2.FilterDescendantsInstances = {script.Parent};
local UnitRay = Mouse.UnitRay.Direction
		local RayCastHit = workspace:Raycast(Camera.CFrame.Position, UnitRay * MaxRange, RayCastFilter1, RayCastFilter2)

Did I do something wrong?

2 Likes

Maybe watch YouTube how to do it.

why use 2 raycastfilters? couldn’t you just

RayCastFilter1.FilterDescendantsInstances = {LocalPlayer.Character, script.Parent};
1 Like

I tried that originally, and it didn’t work, so I tried using two separate filters to see if maybe that was the problem (apparently it’s wasn’t the problem)

workspace:Raycast has a specific amount of parameters, additional values passed as arguments to it will be ignored (unused).

local RayCastFilter1 = RaycastParams.new()
RayCastFilter1.FilterType = Enum.RaycastFilterType.Blacklist
RayCastFilter1.FilterDescendantsInstances = {LocalPlayer.Character, script.Parent}
local UnitRay = Mouse.UnitRay.Direction
local RayCastHit = workspace:Raycast(Camera.CFrame.Position, UnitRay * MaxRange, RayCastFilter1)
1 Like