Problem with raycast ignore

I’m creating a placement script which places a model at the players mouse. The model contains parts which are welded to a node, the node intersects through the parts. I have setup a system which ignores the parts that I don’t want the mouse to detect with ignoreList because if the parts arn’t ignored the model will move towards the camera, due to thinking the part is in front of it i’m guessing. Currently all the script ignored is the Baseplate and part called Node, though I have made it also have the models other bricks on this script. Currently this is what ive done. I have not received any errors. When using just a node without parts it did not do this, which means it has to do with ignoreList.

local ignoreList = {char, clientStructure} -- client structure is the node part char(character)
					local ignore = Build:GetChildren() -- Build is the name of full model
					table.insert(ignore,ignoreList) -- Insert into ignore list
					print(ignore)
					local mouseRay = mouse.UnitRay -- raycast stuff which I barely understand
					local castRay = Ray.new(mouseRay.Origin, mouseRay.Direction * 100)
					local hit, position = workspace:FindPartOnRayWithIgnoreList(castRay, ignoreList)

local newAnglesCFrame = CFrame.Angles(0, math.rad(yOrientation), 0)
					local newCFrame = CFrame.new(position.X, position.Y + yBuildingOffset, position.Z)
					clientStructure.CFrame = newCFrame * newAnglesCFrame

The part is brought towards the mouse in this gif where I tested this:
Gif where node intersects part https://gyazo.com/f3158c76e381c5bbb75c3aa1972f02e1
Gif where node dosnt intersect https://gyazo.com/958bc10d469e25d13029fc7dc1c00b81

If anyone could help me out it would be much appreciated.

2 Likes

Your ignoreList variable is an array, so when you do table.insert(ignore,ignoreList) you’re inserting an array into another array. I believe what you want to do is concatenate the two arrays (merge them). A simple way to do this is

for _,v in pairs(ignoreList) do table.insert(ignore, v) end

which will just add all objects in ignoreList to your ignore array.

Edit: I realized you did the raycast with ignoreList instead of ignore, so in that case just add all the elements in ignore to ignoreList instead.

Thank you so much, I’ve been on this problem for almost two days.

1 Like