Raycasting error

Hey, im having a bug with raycasting. Yes I know that raycast is deprecated, but it still works okay.

Script:

local table_1 = {}
					
					for i,v in pairs(hit.Parent:GetDescendants()) do
						if v:IsA("Part") then
							table.insert(table_1,v)
						end
					end
					
					local newRay = Ray.new(hit.Parent.HumanoidRootPart.CFrame.p, Vector3.new(0,-3,0).unit * 10)
					local hitPart = game:GetService("Workspace"):FindPartOnRayWithIgnoreList(newRay, table_1,false,false)
					
					if hitPart.Material ~= Enum.Material.Air then

error:

Workspace.XurySenpai.Client - Combat [Xury].CombatEvent.Server - Combat [Xury]:343: attempt to index nil with 'Material'

hitPart is nil if the raycast doesn’t detect anything.

Change

if hitPart.Material ~= Enum.Material.Air then

to

if hitPart then -- has same functionality as above