I decided to create a script that simulates MakeJoints but uses constraints instead of old joints. It works well enough, but for some reason for my test cases it doesn't detect that any of the parts are touching. It works when I use it in the trowel tool, but it doesn't work for the old Arcade Machine model (look it up) or my custom test case. It simply doesn't detect that any of the parts are touching. My code:
local module = {}
function module.JoinAdjacentConstraints(brick)
for _, part in pairs(brick:GetTouchingParts()) do
local weld = Instance.new("WeldConstraint")
weld.Part0 = brick
weld.Part1 = part
weld.Parent = brick
end
end
function module.GetSurface(position, object)
local surfaces = {
back = object.CFrame * CFrame.new(0, 0, object.Size.Z);
front = object.CFrame * CFrame.new(0, 0, -object.Size.Z);
top = object.CFrame * CFrame.new(0, object.Size.Y, 0);
bottom = object.CFrame * CFrame.new(0, -object.Size.Y, 0);
right = object.CFrame * CFrame.new(object.Size.X, 0, 0);
left = object.CFrame * CFrame.new(-object.Size.X, 0, 0);
}
local surface = "back"
for side, cframe in pairs (surfaces) do
surface = ((position - cframe.p).magnitude > (position - surfaces[surface].p).magnitude and surface or side)
end
return surface
end
function module.TitleCase(str)
local result=''
for word in string.gmatch(str, "%S+") do
local first = string.sub(word,1,1)
result = (result .. string.upper(first) ..
string.lower(string.sub(word,2)) .. ' ')
end
return result
end
function module.MakeJointsConstraints(brick)
local opposites = {
back = "front";
front = "back";
top = "bottom";
bottom = "top";
right = "left";
left = "right";
}
local axis = {
back = Vector3.new(0, 0, -1);
front = Vector3.new(0, 0, 1);
top = Vector3.new(0, 1, 0);
bottom = Vector3.new(0, -1, 0);
right = Vector3.new(1, 0, 0);
left = Vector3.new(-1, 0, 0);
}
local axis2 = {
back = "Z";
front = "Z";
top = "Y";
bottom = "Y";
right = "X";
left = "X";
}
print(brick)
for _, part in pairs(brick:GetTouchingParts()) do
local surface = module.GetSurface(part.Position, brick)
print(surface)
if brick[string.gsub(module.TitleCase(surface) .. "Surface", "%s+", "")] == Enum.SurfaceType.Glue or brick[string.gsub(module.TitleCase(surface) .. "Surface", "%s+", "")] == Enum.SurfaceType.Weld or (((brick[string.gsub(module.TitleCase(surface) .. "Surface", "%s+", "")] == Enum.SurfaceType.Studs or brick[string.gsub(module.TitleCase(surface) .. "Surface", "%s+", "")] == Enum.SurfaceType.Universal) and (part[string.gsub(module.TitleCase(opposites[surface]) .. "Surface", "%s+", "")] == Enum.SurfaceType.Inlet or part[string.gsub(module.TitleCase(opposites[surface]) .. "Surface", "%s+", "")] == Enum.SurfaceType.Universal)) or ((brick[string.gsub(module.TitleCase(surface) .. "Surface", "%s+", "")] == Enum.SurfaceType.Inlet or brick[string.gsub(module.TitleCase(surface) .. "Surface", "%s+", "")] == Enum.SurfaceType.Universal) and (part[string.gsub(module.TitleCase(opposites[surface]) .. "Surface", "%s+", "")] == Enum.SurfaceType.Studs or part[string.gsub(module.TitleCase(opposites[surface]) .. "Surface", "%s+", "")] == Enum.SurfaceType.Universal))) then
local weld = Instance.new("WeldConstraint")
weld.Part0 = brick
weld.Part1 = part
weld.Parent = brick
end
if brick[string.gsub(module.TitleCase(surface) .. "Surface", "%s+", "")] == Enum.SurfaceType.Hinge then
local hinge = Instance.new("HingeConstraint")
local attach0 = Instance.new("Attachment")
attach0.Axis = axis[surface]
attach0.Axis[axis2[surface]] = math.abs(attach0.Axis[axis2[surface]])
attach0.Position = axis[surface] * brick.Size[axis2[surface]]
attach0.Parent = brick
local attach1 = Instance.new("Attachment")
attach1.Axis = axis[opposites[surface]]
attach1.Axis[axis2[surface]] = math.abs(attach0.Axis[axis2[surface]])
attach1.Position = axis[opposites[surface]] * brick.Size[axis2[surface]]
attach1.Parent = part
hinge.Attachment0 = attach0
hinge.Attachment1 = attach1
hinge.Parent = brick
end
if brick[string.gsub(module.TitleCase(surface) .. "Surface", "%s+", "")] == Enum.SurfaceType.Motor or brick.BackSurface == Enum.SurfaceType.SteppingMotor then
local hinge = Instance.new("HingeConstraint")
local attach0 = Instance.new("Attachment")
attach0.Axis = axis[surface]
attach0.Axis[axis2[surface]] = math.abs(attach0.Axis[axis2[surface]])
attach0.Position = axis[surface] * brick.Size[axis2[surface]]
attach0.Parent = brick
local attach1 = Instance.new("Attachment")
attach1.Axis = axis[opposites[surface]]
attach1.Axis[axis2[surface]] = math.abs(attach0.Axis[axis2[surface]])
attach1.Position = axis[opposites[surface]] * brick.Size[axis2[surface]]
attach1.Parent = part
hinge.Attachment0 = attach0
hinge.Attachment1 = attach1
hinge.Parent = brick
hinge.ActuatorType = Enum.ActuatorType.Motor
hinge.AngularVelocity = 5.5
end
end
end
return module
My test case: https://www.mediafire.com/file/i4bs95r0rpr8pa7/testcase.rbxmx/file
