MakeJoints with WeldConstraint

Given the removal of part surface types coming soon, I am transitioning my building game Free Build over to the constraints system.

I have already looked for solutions on both the developer forum and other sites however haven’t found and workable solutions for what I am doing so far. My current attempt uses GetTouchingParts however upon placing an object, no touching parts are returned from the function therefore no welds are created. Here is the code I have so far:

for _, Touching in pairs(Object:GetTouchingParts()) do
    local NewWeld = Instance.new("WeldConstraint")
    NewWeld.Part0 = Object
    NewWeld.Part1 = Touching
    NewWeld.Parent = Object
    NewWeld = nil
end

Here is how the building looks at the moment for reference with no welds:

Here is the desired outcome however with the old weld system instead of WeldConstraints:

I have also tried Workspace:JoinToOutsiders() however this also uses the Weld instance and not WeldConstraints.

Thank you for reading and any help is appreciated!

2 Likes

Hello.
You can try your method with another part. For example, if your blocks are 4x4x4, you could use an invisible part sized 5x5x5 with its CanCollide property set to true.
Each time you place a block, you would position there this invisible part and call GetTouchingParts on it. This way, you would be able to detect up to (virtually) 26 parts which can surround the target block.

The invisible part should be there for an infinitesimal amount of time so it produces the least interference to collisions, gameplay, etc. (i.e. don’t yield during the iteration).

To avoid repetitive joints, you can call GetConnectedParts on the block and ignore the parts returned. Make sure you don’t weld a part with itself or with other stuff (e.g. a tool)!

Imo, you should only have 1 invisible block per player. Change its position, or even better, set its parent to nil while the player is not placing anything.

3 Likes

Cheers! I tried this however instead used a Region3 using this module so I wouldn’t cause physics issues as my game players can build on anchored bodies:

I then looked through the parts that were in the region and created welds with those! I’ll mark yours as solution as your method would work as well too!
Thank you for your help! :smiley:

1 Like