Raycasting not working


-- RAY

local rayParam = RaycastParams.new()
rayParam.FilterType = Enum.RaycastFilterType.Whitelist
rayParam.FilterDescendantsInstances = rayTable

local result = workspace:Raycast(hit.Parent.HumanoidRootPart.Position,Vector3.new(0,0,2),rayParam)


-- TABLE
for i,v in pairs(game.Workspace:GetDescendants()) do
				if v:IsA("BasePart") and not v:IsDescendantOf(workspace.FX) and not v.Parent:FindFirstChild("Humanoid") then
					table.insert(rayTable,v)
                                        print(v)
				end
			end

Why is the raycast not working? There is no result even there clearly are parts. I printed “v” and it gave the parts i wanted, but the raycast doesn’t work. No error either, yes I tried putting the target position to a higher number but still no result. This used to work when I had it as a blacklist and I did my loop differently.

I don’t see where you are using the RayCasting actually (result).
Anyways, the problem might be the direction. You are using Vector3.new(0,0,2) which pretty much doesn’t mean anything. What do you want the direction to be like? In front of the part? Back?

You should check if there is an actual result for the RayCast that you are using?

if result then
    print("Object/terrain hit:", result.Instance:GetFullName())
	print("Hit position:", result.Position)
	print("Surface normal at the point of intersection:", result.Normal)
	print("Material hit:", result.Material.Name)
else
    print("There is no result")
end