Raycasting: Unable to cast value to Object

I am trying to have a turret shoot lasers at nearby players, but I am stuck: when I try to use “FindPartOnRayWithIgnoreList”, it errors that “Unable to cast value to Object”. I assumed that I’m passing the ignorelist incorrectly, but I seem to not understand where.

local map = workspace.Map:FindFirstChild("Map")
		local ignorelist = {}
		if map then --
			local mapparts = map:GetDescendants()
			for _,v in pairs(mapparts) do
				if v:IsA("Part") or v:IsA("MeshPart") or v:IsA("UnionOperation") then
					if v.CanCollide == false then
						table.insert(ignorelist,v)	
					end
				end
			end
		end
		--add ignoreparts
		for i,v in pairs(ignoreparts) do
			table.insert(ignorelist,v)
		end

		local ray = Ray.new(FiringCap.Position,FiringCap.CFrame.LookVector * 100)
		local part, position = workspace:FindPartOnRayWithIgnoreList(ray, ignorelist) --errors

It seemed that I couldn’t find relatable problems with the list.

Hey, what does the “ignoreparts” table equal?

Oh, I see the problem now that you mentioned it, it was a list of strings, which the GetPartOnRay can’t take

local ignoreparts = {
	"HumanoidRootPart",
	"PivotBase",
	"Head",
	"UpperTorso",
	"UpperTorsoWeld",
	"MotorTop",
	"ConnectTop"
}

So then, would it be better to save the list as the respective Parts?

Yup, you can’t ignore Strings with a Ray, they have to be parts so instead of those being strings, have them be the actual parts

I’ll itterate through the ignoreparts using :FindFirstChild(), thanks!

No problem, if you need any more help with it, let me know :slight_smile: