Help with Raycast ignore list

hello, i have a raycast script and i need help adding a ignore list, i need to ignore everything in a folder since its getting in the way of the raycast, any help?


local player = game.Players.LocalPlayer
local char = player.Character
local hrp = char:WaitForChild("HumanoidRootPart")
local RunService = game:GetService("RunService")

local NeedtoBeIgnored = game.Workspace.PassThroughs -- Folder that has the parts that need to be ignored

RunService.RenderStepped:Connect(function(step)
	local ray = Ray.new(hrp.Position, ((hrp.CFrame + hrp.CFrame.LookVector * 2) - hrp.Position).Position.Unit * 1000)
	local ignoreList = char:GetChildren()

	local hit, pos = game.Workspace:FindPartOnRayWithIgnoreList(ray, ignoreList)
	
	if hit then
		print(hit)
		if char:WaitForChild("Camera") then
			if char:WaitForChild("Camera").Handle.SpotLight.Enabled == true then
				if hit.Parent.Name == "Monster" then
					game.ReplicatedStorage.Blinded:FireServer()
				end
			end
		end
	end
end) 

FindPartOnRay is now deprecated.
Raycast is the one to use.

Here is the documentation
You’ll also want RaycastParams

You should use workspace:Raycast() instead of Ray.new(), here is an example:

local part = workspace.part
local ignorelist = {workspace.otherpart1,workspace.otherpart2}
local origin = part.Position
local direction = part.CFrame.LookVector
-- You don't need to add the position to the direction as the function already does that.
local params = RaycastParams.new()
params.FilterDescendantsInstances = ignorelist 
-- ignorelist HAS to be a table or else this will not work.

local result = workspace:Raycast(origin,direction,params)

This might be helpful:

local RCP = RaycastParams.new()
	RCP.FilterDescendantsInstances = {NeedstoNeIgnored}
	RCP.FilterType = Enum.RaycastFilterType.Blacklist

at the end of your Raycast, im pretty sure you add this saying ,RCP

	local ray = Ray.new(hrp.Position, ((hrp.CFrame + hrp.CFrame.LookVector * 2) - hrp.Position).Position.Unit * 1000, RCP)

Also what do you mean in Passthroughs?
If its what I think it is:
You might be able to turn off CanTouch so the mouse cant touch it?

No, the RaycastParams.RaycastFilterType is already defaulted to Enum.RaycastFilterType.Blacklist so it is not really needed.

I don’t think he is using the player’s cursor. But if he is, then just do this:

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
mouse.TargetFilter = NeedtoBeIgnored -- Yes, it works for folders.

I think Passthroughs is basically just a folder that has parts that will be ignored by the raycast.

I think this should work, I replaced Ray.new() with workspace:Raycast()

local player = game.Players.LocalPlayer
local char = player.Character
local hrp:BasePart = char:WaitForChild("HumanoidRootPart")
local RunService = game:GetService("RunService")

local NeedtoBeIgnored = game.Workspace.PassThroughs -- Folder that has the parts that need to be ignored

RunService.RenderStepped:Connect(function(step)
	local origin = hrp.Position
	local direction = hrp.CFrame.LookVector * 1000
	local params = RaycastParams.new()
	params.FilterDescendantsInstances = NeedtoBeIgnored:GetChildren()
	
	local result = workspace:Raycast(origin,direction,params)
	-- Properties of result :
	-- result.Instance = The part it hit
	-- result.Position = The position on where it hit
	-- result.Distance = The distance between the start and the end
	-- result.Material = The material of the part it hit
	-- result.Normal = The rotation of the surface it hit
	
	if result then
		print(result.Instance,result.Position)
		if char:FindFirstChild("Camera") then -- Don't use :WaitForChild() in if statements. This will cause an infinite yield.
			if char:FindFirstChild("Camera").Handle.SpotLight.Enabled == true then
				if result.Instance.Parent.Name == "Monster" then
					game.ReplicatedStorage.Blinded:FireServer()
				end
			end
		end
	end
end)