Why do I keep getting an error with table.insert?

this is the error:
image

here is the line causing the error:

	table.insert(neighbors, workspace:FindPartOnRay(Ray.new(currentBlock.Position, Vector3.new(-1, 0, 0))))

I can’t figure out what is wrong, it’s using only the 2 arguments in the function…

I assume that returns more than one argument

I would like to add that if the function does and NEEDS to return more than two arguments, you could also make it return a table/array instead.

1 Like

Switching to workspace:Raycast will fix the issue for you, but you will need to change some parts of your code, like result.Instance.

1 Like

I tried to do something similar, but I used table.unpack like you did FindPartOnRay. The thing is, we’re trying to insert a Tuple consisting of several variables. Combine them into a table and insert them to another one or insert separately.

Your ray direction is Vector3.new(-1, 0, 0) that is length 1, so the ray is only one stud long. That means it will almost always miss. You need to scale the direction by the distance you want to check.

local neighbors = {}
local currentBlock = workspace.CurrentBlock

local part = workspace:FindPartOnRay(Ray.new(currentBlock.Position, Vector3.new(-1,0,0) * 100))
if part then
	table.insert(neighbors, part)
end

Now I’m lost too .. :grinning_face_with_smiling_eyes: .. these one line help me questions.