Raycast not detecting parts of other players

For some reason this script refuses to detect the body parts of other characters on the map. Currently, it is fired from the player’s HumanoidRootPart in a straight line. How can I fix this? Thanks!

This picture shows several attempts to hit another character, with each attempt clearly failing:

Code:

local Character = Player.Character

local Params = RaycastParams.new()
Params.FilterType = Enum.RaycastFilterType.Exclude
Params.FilterDescendantsInstances = {Character}
						
local rayOrigin = HumanoidRootPart.CFrame.Position
local rayDirection = Vector3.new(0, 0, 20)
						
local RayResult = game.Workspace:Raycast(rayOrigin, rayDirection, Params)

if RayResult then
	HumanoidRootPart.Position = RayResult.Position
	print("Hit! Teleporting studs: "..tostring(RayResult.Distance)..", Instance name: "..tostring(RayResult.Instance))
							
	local p = Instance.new("Part")
							
	p.Anchored = true
	p.CanCollide = false
	p.Size = Vector3.new(0.1, 0.1, RayResult.Distance)
	p.CFrame = CFrame.lookAt(rayOrigin, RayResult.Position)*CFrame.new(0, 0, -RayResult.Distance/2)
							
	p.CanQuery = false
							
	p.Parent = game.Workspace
else
	local p = Instance.new("Part")
	local distance = (rayOrigin - (HumanoidRootPart.CFrame * CFrame.new(0, 0, -20)).Position).Magnitude
							
	p.Anchored = true
	p.CanCollide = false
	p.Size = Vector3.new(0.1, 0.1, 20)
	p.CFrame = CFrame.lookAt(rayOrigin, (HumanoidRootPart.CFrame * CFrame.new(0, 0, -20)).Position) * CFrame.new(0, 0, -distance/2)
							
	p.CanQuery = false
							
	p.Parent = game.Workspace
							
	HumanoidRootPart.CFrame = HumanoidRootPart.CFrame * CFrame.new(0, 0, -20)
	print("No hit! Teleported.")
end

You blacklisted the entire player which is why none of the rays are detecting it lol

The blacklist is referring to the character that casts the raycast, which I intend to hit other characters. The character in the picture is not the player character that is in the blacklist. I don’t know why it doesn’t work

I cannot include the entire script where this portion comes from as it it is rather long and is mostly concerned with non-raycast related things.

The ray seems to cast fowards from the HumanoidRootPart since the raycast actually is able to detect solid walls in front of the character. It is only when the obstacle is another player’s character that I run into the strange issue.

The other character isn’t referenced in the code as I intend to use the raycast to find the other player.

The intended behavior looks something like this, the players are the circles facing the black arrow:

but in reality, the orange raycast goes through the other player (as seen in the OP screenshot)

I really do not know why this happens

Check if the other player’s bodyparts have .CanQuery on. If it is off then that means the part is universally blacklisted from raycasts.

I tried turning on canQuery for every part in the workspace on several occasions but it still doesn’t work for some reason

Do you mind sending me a copy of the place file?

I don’t think I can do that unfortunately :frowning: I think ill try figuring it out next time

I tried remaking what you did and it seems to work fine:
(It says Handle because it is hitting the accessories)

Baseplate.rbxl (45.0 KB)

I’ll check it out when I have the time, hopefully with this I can find out what’s wrong with my attempt