Removing the need for a bunch of invisible parts

In my game, I use a lot of invisible parts for things like hitboxes on objects that the players can place. This interferes with the mouse because whenever somebody tries placing something, their mouse hit location will be on top of the invisible part, which is annoying for players. What are some workarounds that allow me to remove these invisible parts or at least make it so they don’t interfere with the player’s mouse.

The among of completely transparent parts is dynamic and could be a very high number. I’m trying to keep any and all calculations involving the invisible parts very efficient. How would I accomplish a workaround for this issue? Possibly Region3 could work as a replacement?

if you wanted to there’s a filter option for the mouse i believe

Try this:

if mouse.hit.Name ~= invisiblePartsName then


end

And if you don’t use mouse.hit then replace it with whatever you are using

I’ve tried this solution in the past, but the amount of invisible parts is dynamic and would be a large amount often. I use a raycasting mouse solution meaning every frame I would have to raycast ignoring quite a few instances. Not sure of the performance impact on that.

If I’m setting the position of a model to the mouse’s hit (which I am), and wouldn’t if the hit’s name is a given string then the model’s position wouldn’t update at all if it found an invisible part. This would end up being more annoying for players.

Why don’t you try collision groups

Collision groups wouldn’t work for this case because I’m setting the position of model using what the mouse would return. The collision of the model to the invisible part isn’t the issue, the position in which the mouse returns is. Because of this, as I stated in the original post, I’d likely need to find a workaround to not use invisible parts. This is where I need the assistance.

local mouse = game.Players.LocalPlayer:GetMouse()

local function findInvis()
local parts =  {}
	for _, part in pairs(game.Workspace:GetDesendents())do
		if part:IsA("BasePart") then
			if part.Transparency == 1 and part.Name == "hitbox" then 
				table.insert(parts,part) 
			end
		end
	end
return parts
end


local local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.BlackList
raycastParams.FilterDescendantsInstances = findInvis
raycastParams.IgnoreWater = true

local raycastResult = workspace:Raycast(game.Workspace.CurrentCamera.CFrame.Position, mouse.Hit.Position, raycastParams)

if raycastResult then
	print("Object/terrain hit:", raycastResult.Instance:GetFullName())
	print("Hit position:", raycastResult.Position)
	print("Surface normal at the point of intersection:", raycastResult.Normal)
	print("Material hit:", raycastResult.Material.Name)
else
	print("Nothing was hit!")
end

im not sure if this would work but if you name all the invisible parts hitbox and they are invisble then this will igonore them
it uses the cameras cframe for starting position, but you could also you something like the players humanoidrootpart

edit my bad don’t use whitelist use black list i’ve fixed the code for this part

you could also ignore the list and use collision groups to ignore parts

RaycastParams.CollisionGroup

This code would be extremely inefficient because going through the all of the workspace’s desendants every frame would end up causing lots of lag. In regards to RaycastParams.CollisionGroup, that could be a viable solution (didn’t know that it existed lol). Due to the amount of invisible parts being dynamic, I could specify to avoid a special collision group applied to invisible parts. I’ll give it a try and see how it goes.