Ray ignoring and CollectionService

Hi. I’m trying to get my Ray to ignore tagged items. “FindPartOnRayWithIgnoreList” line is causing an error. Can a ray not ignore tags or do I have something setup wrong?

local CollectionService = game:GetService('CollectionService')

function CreateRay()
	local IgnoreTag = CollectionService:GetTagged('RayIgnore')
	local Ray = Ray.new(Bla1,Bla2)
	local Hit,Position = workspace:FindPartOnRayWithIgnoreList(Ray,{Character,IgnoreTag})
	if Hit then
		print(Hit)
	end
end

CreateRay()

It takes an array of Instances. You have {Instance, Array}

Try caching the tagged items and using table.insert to add the Character to the same 1 dimensional array.

1 Like

So basically I just need to create another table with the tagged instances?

Try this

local CollectionService = game:GetService('CollectionService')

function CreateRay()
	local ignoreList = CollectionService:GetTagged('RayIgnore')
    table.insert(ignoreList, Character)
	local Ray = Ray.new(Bla1,Bla2)
	local Hit,Position = workspace:FindPartOnRayWithIgnoreList(Ray,ignoreList)
	if Hit then
		print(Hit)
	end
end

CreateRay()

You should create and cache the ignoreList outside of the CreateRay function to improve performance, but this should get it working for you.

2 Likes

Wow! It works! Thank you so much for explaining!