WallCheck Problem

Hello! I am writing a wall ckeck function to detemine whether or not there is a part or “wall” in between two characters:

local function ReturnWallCheck(CharacterModel, ToVector)
	
	local GetParts = {}
	for i,v in pairs(Character:GetDescendants()) do
		table.insert(GetParts, v)
		if v:IsA("Part") or v:IsA("MeshPart") then
			table.insert(GetParts, v)
		end
	end
	
	local r_ = RaycastParams.new()
	r_.FilterDescendantsInstances = GetParts
	r_.FilterType = Enum.RaycastFilterType.Blacklist
	local rayresult = workspace:Raycast(Hrp.Position, (ToVector - Hrp.Position).Unit * 10000000)
	if rayresult then
		local RayInstance = rayresult.Instance
		print(RayInstance.Name, RayInstance.Parent.Name)
		if RayInstance.Parent == CharacterModel then
			return true
		end
		
		if RayInstance:IsDescendantOf(CharacterModel) then
			return true
		else
			return false
		end
	end
end

Sometimes it will print parts that belong to your character which means that it is not working properly. It is supposed to make sure that none of the parts in your character are detected.
Thanks,

Heres what ive used before and i think it works

local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {game.Players.LocalPlayer.Character}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist

in your code it might look like:

local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {game.Players.LocalPlayer.Character}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
	local rayresult = workspace:Raycast(Hrp.Position, (ToVector - Hrp.Position).Unit * 10000000, raycastParams)
	if rayresult then
		local RayInstance = rayresult.Instance
		print(RayInstance.Name, RayInstance.Parent.Name)
		if RayInstance.Parent == CharacterModel then
			return true
		end
		
		if RayInstance:IsDescendantOf(CharacterModel) then
			return true
		else
			return false
		end
	end

Im not 100% sure if this would work but its worth a try i guess :slight_smile:

local Enumeration = Enum
local Workspace = workspace

local function PlayerObstructionCheck(Player1, Player2)
	local Character1, Character2 = Player1.Character, Player2.Character
	if not (Character1 and Character2) then return end
	local Position1, Position2 = Character1:GetPivot().Position, Character2:GetPivot().Position
	
	local Parameters = RaycastParams.new()
	Parameters.FilterDescendantsInstances = {Character1, Character2}
	Parameters.FilterType = Enumeration.RaycastFilterType.Blacklist
	
	local Result = Workspace:Raycast(Position1, (Position2 - Position1), Parameters) --If 'Result' is non-nil then the two players are obstructed.
end

My problem is, is when I called the Workspace:RayCast(), I forgot to put my RaycastParams in the third parameter.