Raycast Returning Tool Or Accessories

  1. What do you want to achieve?
    Raycast that checks for another humanoid (especially npc)

  2. What is the issue?
    It keeps returning the tool itself or the player’s accessories.

  3. What solutions have you tried so far?
    I have looked almost everywhere for solutions and tried them all, but none of them worked

-- raycasting things
local mouse = player:GetMouse()
local origin = character.Head
local AskingRange = 16



local cantAsk = {
	tool.Handle,
	character:GetDescendants(),
	character:GetChildren()
}

local rcParams = RaycastParams.new()
rcParams.FilterType = Enum.RaycastFilterType.Exclude
rcParams.FilterDescendantsInstances = cantAsk

function TimeToAsk(player, mousePos, originPos)
	
	print("It was " .. player.Name)

	local direction = (mousePos - originPos).Unit * AskingRange

	local result = workspace:Raycast(originPos, direction)

	if result then
		print(result.Instance.Name)
		
	end
end

Note: Everything else works fine, it is just this piece of code that I need help with.

Although you defined the raycast parameters, you didn’t reference them in the above statement. So try:

local result = workspace:Raycast(originPos, direction, rcParams )

works like a charm now, thank you

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.