Unable to cast value to object

local castRay = Ray.new(mouseRay.Origin, mouseRay.Direction * 1000)
							
local hit, position = game.Workspace:FindPartOnRayWithIgnoreList(castRay, rayCastIgnoreList)

Why does this error appear?
image

Which line exactly is erroring? It’s one of the parameters of the functions that’s wrong, for sure.

Line 264, which is the second line in what i sent. I know its one of the parameters but I dont know which one or what is wrong with it.

Can you show the line where you localled rayCastIgnoreList?
It seems like it’s not a table with objects.

rayCastIgnoreList = {ConnectionList, WireList}

for _, plr in pairs(game.Players:GetPlayers()) do
	if plr and plr.Character then
		table.insert(rayCastIgnoreList, plr.Character)
	end
end

local mouseRay = Mouse.UnitRay
local castRay = Ray.new(mouseRay.Origin, mouseRay.Direction * 1000)

local hit, position = game.Workspace:FindPartOnRayWithIgnoreList(castRay, rayCastIgnoreList)

Right now the two lists, ConnectionList and WireList are empty.

If ConnectionList and WireList are NOT objects (if they are tables or something), then it will error, as the rayCastIgnoreList must only contain existing objects.

ConnectionList and WireList are both tables, right? that’s likely your problem.
also use workspace:Raycast, because Ray.new is deprecated

1 Like

Thanks. I will just use for loops to add their items into the main table.

1 Like

Does it support ignorelists as well?

Yes,

local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Blacklist
params.FilterDescendantsInstances = {workspace.ignore}

it also supports collisiongroups