PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

MakeJoints

Goes through all BaseParts in the Model. If any part’s side has a SurfaceType that can make a joint it will create a joint with any adjacent parts.

This function will not work if the Model is not a descendant of Workspace. Therefore developers must first ensure the Model is parented to Workspace before using MakeJoints.

Joints are broken if enough force is applied to them due to an Explosion, unless a ForceField object is parented to the model. For this reason, they are often used to make simple destructible buildings and other models.

Returns

Return Type Summary

Code Samples


Simple Joint Creation

This code sample demonstrates creation of joints on two parts that are siblings of the script (PartA and PartB). It uses MakeJoints on two touching parts with compatible surface types (Studs and Inlet).

local partA = script.Parent.PartA
local partB = script.Parent.PartB

-- Move PartB on top of PartA
partB.CFrame = partA.CFrame * CFrame.new(0, partB.Size.Y / 2 + partA.Size.Y / 2, 0)
-- Studs and Inlet will make joints
partA.TopSurface = Enum.SurfaceType.Studs
partB.BottomSurface = Enum.SurfaceType.Inlet
-- Automatically create a joint between PartA and PartB
partA:MakeJoints()

Model MakeJoints

This code sample demonstrates how joints can be made using the Model:MakeJoints function.

A model is instanced, with two parts on top of each other. The top part is anchored and the bottom part is not. Normally, when parented to the Workspace the bottom part would fall to the Baseplate.

However, as TopSurface property of the bottom part is set to Enum.SurfaceType.Weld, this means that when Model:MakeJoints is ran a connection is made between them.

Therefore the bottom part does not drop until the joints in the model are broken. This is often done using Model:BreakJoints, but in this example the connection is broken using an explosion.

local model = Instance.new("Model")

-- create one part on top of another
local topPart = Instance.new("Part", model)
topPart.Size = Vector3.new(5, 1, 5)
topPart.Position = Vector3.new(0, 10, 0)
topPart.BrickColor = BrickColor.new("Bright green")
topPart.Anchored = true -- anchor the top part

local bottomPart = Instance.new("Part", model)
bottomPart.Size = Vector3.new(8, 1, 8)
bottomPart.Position = Vector3.new(0, 9, 0)
bottomPart.BrickColor = BrickColor.new("Bright green")
bottomPart.Anchored = false -- leave bottom unanchored

-- set the part's surfaces
topPart.BottomSurface = Enum.SurfaceType.Smooth -- 'Weld' to create a joint
topPart.TopSurface = Enum.SurfaceType.Smooth
bottomPart.BottomSurface = Enum.SurfaceType.Smooth
bottomPart.TopSurface = Enum.SurfaceType.Weld -- 'Weld' to create a joint

-- parent the model to the workspace
model.Parent = game.Workspace

-- make the joints
model:MakeJoints()

wait(2)
-- unanchor the bottom part - part does not fall
print("Unanchored!")
bottomPart.BrickColor = BrickColor.new("Bright red")
bottomPart.Anchored = false

wait(2)
-- break the joints using an explosion - part falls
local explosion = Instance.new("Explosion")
explosion.Position = bottomPart.Position
explosion.Parent = game.Workspace