Error while getting target HumanoidRootPart?

Hello, fellow devs,

I am trying to get a HumanoidRootPart by gettign the nearest target, but something wrong with my script.

Getting the target:

Getting the path:

Loop

image

try using this

function GetClosestVisiblePlayer()
	local closest1 = nil
	local root2 = nil
	local dist = math.huge
	for i,v in pairs(ps:GetPlayers()) do
		local ch = v.Character
		if ch then
			local root = ch.HumanoidRootPart
			local r = RaycastParams.new()
			r.FilterType = Enum.RaycastFilterType.Blacklist
			r.FilterDescendantsInstances = {
				script.Parent,
				workspace.Items,
				Regions
			}
			local r2 = workspace:Raycast(Eyes.Position,(root.Position-Eyes.Position).Unit*9999,r)
			if r2 and r2.Instance and r2.Instance.Name == "HumanoidRootPart" then
				local d2 = (root.Position - script.Parent.HumanoidRootPart.Position).Magnitude
				if d2 < dist then
					dist = d2
					root2 = root
					closest1 = v
				end
			end
		end
	end
	return closest1,root2,dist
end

what is Regions? Is it something a part or what

everything in the FilterDescendantsInstances table is what you want the script to see through, so workspace would be everything in workspace, workspace.Windows would be everything in workspace.Windows, ect