How to make a Humanoid cancel its move to if it's move to position is in a block or in terrain?

I want to make my humanoid cancel its move to if it’s trying to go into terrain or a block, the problem is, I don’t know how to sense if the position is inside a block or terrain. Since my npc moves to randomized positions(using math.random in relation to the HumanoidRootPart’s position). It tends to try to get into walls or into the ground, breaking the realism of the game. How would I go about fixing this?

Here’s my script:

local PathService = game:GetService("PathfindingService")

local Char = script.Parent
local Hum = Char.Humanoid

local body = script.Parent:FindFirstChild("HumanoidRootPart") or script.Parent:FindFirstChild("Torso")--I didn't use this part of the tutorial lol

while true do
	local Root = script.Parent:FindFirstChild("HumanoidRootPart")
	if Root then
		local Destination = Vector3.new(Root.Position.X + math.random(-200,200),Root.Position.Y + math.random(-200,200),Root.Position.Z + math.random(-200,200))
	local Path = PathService:CreatePath()
	Path:ComputeAsync(body.Position, Destination)
	local Waypoints = Path:GetWaypoints()
	for k, Waypoint in pairs(Waypoints) do
		Hum:MoveTo(Waypoint.Position)
		Hum.MoveToFinished:Wait()
	end
	end
	wait(0.01)
end