Trouble with raycasting

I’m having trouble making a raycast from one part to another part. I’ve taken a look at some other people’s similar problems but none of their solutions seem to be working for me.

    local params =
	params.FilterType = Enum.RaycastFilterType.Blacklist
	params.FilterDescendantsInstances = {script.Parent}
	local ray
	local tries = 10
		ray = game.Workspace:Raycast(script.Parent.Torso.Position, (playerr.Character.Head.Position - script.Parent.Chest.Position) * 100, params)
		tries -= 1
	until ray and ray.Instance.Parent == plr.Character or tries <= 0
	if ray.Instance.Parent == plr.Character then

note that it is casting, just it only works from very short distances and hardly ever hits

1 Like

If you are casting from the torso position, shouldn’t the direction be from the torso to the head?

Is the chest offset from the torso? If so it will cause the direction to be offset as well and make the ray not hit.

I would also recommend visualize the ray as a part (search up how to do that if needed) and posting a screenshot of it in the post.

Hi, this is happening because the ray is colliding with the torso that it is being spawned from. Add script.Parent.Parent to the blacklist:

params.FilterDescendantsInstances = {script.Parent.Parent}

This shouldn’t be necessary, FilterDescendantsInstances as its name suggests filters all of an instances descendants, for example FilterDescendantsInstances = {Character} would filter all of a character’s descendants.

1 Like