How to "offset" :GetTouchingParts?

So i’m making a placement system and i’m welding the part i’m placing to every part it’s touching with this code:

local touching = placedPart:GetTouchingParts()
		if touching and #touching > 0 then
			for _,part in pairs(touching) do
				if not table.find(plr.Character:GetChildren(),part) then
					local weld ="WeldConstraint")
					weld.Parent = placedPart
					weld.Part0 = placedPart
					weld.Part1 = part

However in the placing script, when the part i’m placing isn’t rotated it is placed “against” the wall but is not touching it so it doesn’t weld. How do i make :GetTouchingParts (or some other function) get the parts touching a slightly larger area (like 0.001 studs on all sides) so it also gets the parts the placing part is placed against?

you can give them a hitbox. Basically a slightly larger transparent part and check touching parts in the hitbox.

1 Like

This should help

1 Like

So in the script i would make a new part named hitbox that has the same CFrame as the part i’m placing but a slightly larger size, then check for touching parts of hitbox and then destroy hitbox?

Yes, but the part can also be rotated and with :GetPartsInBox you can’t specify a rotation.

Atleast i don’t think so?

Yeah you can rotate. It uses CFrame. This is the solution i used for my placement system.

1 Like

Oh ok i will try that then. Thanks!

1 Like

yes. depending on how often you need to do checks it may be more beneficial to not delete the hitbox. Also, for more specific customization you can manually size the hitbox in studio and then you don’t have to create it through a script.

1 Like