Gun raycast always detecting baseplate

My raycast keeps detecting the baseplate, I want to detect if you hit a enemy,code with problems:

local Item = MS.Target
	local Origin = HRP
	local FCT = coroutine.wrap(function()
		local FRY = Ray.new(Origin.Position,(Item.Position - Origin.Position))
		local Hit, position = workspace:FindPartOnRayWithIgnoreList(FRY,false)
			print(Hit)
end)

MS meaning mouse HRP meaning humanoid root part

Try using RaycastParams instead of Ray.New. So with the RaycastParams, it lets you blacklist any parts on the game to not detect on the ray.

1 Like

Here’s is how you use it.

local RayParams = RaycastParams.new()
RayParams.FilterType = Enum.RaycastFilterType.Blacklist
RayParams.FilterDescendantsInstances = {insert the things u want to blacklist}

 local RayHit = game.Workspace:Raycast(position, direction, RayParams)
            if RayHit then
                print(RayHit.Instance)
            end
1 Like

ill try it,thanks for the help

like this?

local Item = MS.Hit
	local Origin = HRP
	local RayParams = RaycastParams.new()
	RayParams.FilterType = Enum.RaycastFilterType.Blacklist
	RayParams.FilterDescendantsInstances = {Origin,game.Workspace.Baseplate}
	local FCT = coroutine.wrap(function()
		local RayHit = game.Workspace:Raycast(Origin,Item.Position - Origin.Position,RayParams)
		if RayHit then
			print(RayHit.Instance)
		end

it said unable to cast instance to vector3

What line
OnlyTwentyCharacters

sorry im dumb i forgor the pos in origin

2 Likes