Question regarding FindPartsWithIgnoreList()

So I was creating a turrent and before I work on it’s shooting and moving, I came across something, FindPartsOnIgnoreList(). So I’m new to ray casting but I know how to do it.

What I want to achieve is that I want the Ray not to do something what I want if there is an object in front of it but I somehow managed to achieve that but still, I want to know how.

local ServerStorage = game:GetService("ServerStorage")

local Rocket = ServerStorage:WaitForChild("Rocket")

local TripleAAAGun = script.Parent

-- Toggles

local FireRate = 1
local BulletDamage = 45
local BulletVelocity = 175
local DistanceToShoot = 150

local Target = nil

local function detectTarget()
	
	for i, v in ipairs(workspace:GetChildren()) do
		
		local Humanoid = v:FindFirstChild("Humanoid")
		local HRP = v:FindFirstChild("HumanoidRootPart")
			
		if Humanoid and HRP and (TripleAAAGun.Position - HRP.Position).Magnitude < DistanceToShoot then
			
			
			local ray = Ray.new(TripleAAAGun.Position, (HRP.Position -  TripleAAAGun.Position ).Unit * 500)
			local hit, position = workspace:FindPartOnRayWithIgnoreList(ray, {TripleAAAGun})
			
			if hit == HRP then
				print("Ray has hit " .. HRP.Parent.Name)
				Target = HRP
			else
					print("False")
			end
		end
	end
end

while true do
	detectTarget()
	wait()
end
local hit, position = workspace:FindPartOnRayWithIgnoreList(ray, {TripleAAAGun})

So workspace:FindPartOnRayWithIgnoreList requires a ray and then a table for what to ignore. So how does it work in the first place if it ignores the gun it self which is script.Parent?

It should ignore anything in the table.
Including it’s self. (If you did include it’s self it in the table)

Not the answer I expected, why does it print that the ray hit my HRP when I’m ignoring the turrent?

Can you try to explain your achievement a bit better please?
Sorry, I’m having a hard time figuring out what your trying to achieve.

1 Like

I writing a whole thing about why the ignore list is required, but this reply added information that wasn’t in the post.

The raycast is likely being obstructed by the player. You should add the Character of the player that is firing the gun inside of the ignore list as well, so you can’t shoot yourself.

1 Like

So, there is a wall between a turrent and my script is to not make the turrent shoot if there is something in front of it using RayCasting. I managed to acomplish it by this line:

local hit, position = workspace:FindPartOnRayWithIgnoreList(ray, {TripleAAAGun})

But I want to know that how does it ignore the part when it is ignoring it self given that in the table, is the triple AAA gun it self? Everything seems to work as expected but how? That’s my point here.

Are you asking how the raycast is working despite you ignoring the gun?

Raycasts are independent of objects. It’s just that for your case here, you need to create the ray relative to the position of the gun. The gun part itself is irrelevant when creating the ray, the only important thing is its position.

Ignoring the gun part doesn’t do anything to the ray other than allowing it to not be obstructed by the part its being fired from.

1 Like

“Are you asking how the raycast is working despite you ignoring the gun?” Yes.

If it’s ignoring the wall, then make sure that the wall is not a child of the part/model you are ignoring.

The raycast will work like an regular raycast just ignoring the selected objects you put in the ignore list.
I recommend reading these: